Skip to content

Commit

Permalink
Merge pull request #299 from KateOrient/feature/electron-fixes
Browse files Browse the repository at this point in the history
Move redirect to a separate method
  • Loading branch information
KateOrient authored Nov 16, 2023
2 parents 64399f1 + 6014f63 commit dd7242b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 15 additions & 2 deletions src/common/services/fileService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import SparkMD5 from 'spark-md5';
import { get, upload } from './api';
import { JOB_OLD_FILE } from '../store/constants';

const { REACT_APP_API_ROOT } = process.env;
const { REACT_APP_API_ROOT, PUBLIC_URL } = process.env;

export const getInfo = () => {
const url = `${REACT_APP_API_ROOT}/status/file-storage/info`;
Expand Down Expand Up @@ -71,4 +72,16 @@ const calculateContentMD5 = file =>
loadNext();
});

export const getFileLinkById = id => `${REACT_APP_API_ROOT}/files/${id}`;
export const redirectToStartScreen = () => {
const oldFileName = sessionStorage.getItem(JOB_OLD_FILE);
let location = window.location.pathname;
if (!PUBLIC_URL.endsWith('/')) {
location = location.replace(/\/$/, '');
}
if (oldFileName && location !== PUBLIC_URL && location !== `${PUBLIC_URL}/new-job/files`) {
// Redirect to start screen and hide Loading view
window.location.replace(PUBLIC_URL);
return true;
}
return false;
};
13 changes: 3 additions & 10 deletions src/common/store/rootStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './rootReducer';
import { JOB_NEW_FILE, JOB_OLD_FILE, JOB_LINK, JOB_MODE, JOB_STATUS } from './constants';
import { JOB_NEW_FILE, JOB_LINK, JOB_MODE, JOB_STATUS } from './constants';
import { finishAppStartup, setFileUploadMode } from './application/actions';
import { updateServerStatus, updateWorkerServiceStatus } from './serverInfo/actions';
import { addPdfFile } from './pdfFiles/actions';
Expand All @@ -13,6 +13,7 @@ import { getJobStatus } from './job/selectors';
import { getUnsavedFile } from './pdfFiles/selectors';
import { isFileUploadMode, isLocked } from './application/selectors';
import { setLink } from './pdfLink/actions';
import { redirectToStartScreen } from '../services/fileService';

export default function configureStore() {
const store = createStore(rootReducer, applyMiddleware(thunk));
Expand Down Expand Up @@ -54,15 +55,7 @@ export default function configureStore() {
store.dispatch(updateWorkerServiceStatus());

// Redirect to start screen if there is old file
const { PUBLIC_URL } = process.env;
const oldFileName = sessionStorage.getItem(JOB_OLD_FILE);
let location = window.location.pathname;
if (!PUBLIC_URL.endsWith('/')) {
location = location.replace(/\/$/, '');
}
if (oldFileName && location !== PUBLIC_URL && location !== `${PUBLIC_URL}/new-job/files`) {
// Redirect to start screen and hide Loading view
window.location.replace(PUBLIC_URL);
if (redirectToStartScreen()) {
return;
}

Expand Down

0 comments on commit dd7242b

Please sign in to comment.