Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(electron): fix persisted actions path #295

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function saveAction(action) {
}

// Loads a redux action in a local file for offline usage
function loadAction(actionType) {
function loadAction(actionType, pathToFile) {
const loadActionRemoteFn = remote.require('./load-action');
return loadActionRemoteFn(actionType);
return loadActionRemoteFn(actionType, pathToFile);
}

// The context of the preload script and the browser windows context are both
Expand Down
1 change: 1 addition & 0 deletions src/scripts/libs/electron/get-offline-tiles-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function getOfflineTilesUrl(): string {
}

return window.cfs.getDownloadsPath(
'downloads',
'{id}',
'tiles',
'{timeIndex}',
Expand Down
17 changes: 11 additions & 6 deletions src/scripts/libs/electron/offline-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,30 @@ export const offlineSaveMiddleware: Middleware = () => (
// dispatched
export const offlineLoadMiddleware: Middleware = () => (
next: Dispatch<AnyAction>
) => (action: AnyAction) => {
) => (dispatchedAction: AnyAction) => {
const actionToLoad = actionsToPersist.find(
({error}) => error === action.type
({error}) => error === dispatchedAction.type
);

// when the incoming action did fail and is one we probably saved before,
// try to load it from the filesystem and return the success action instead
// of the error action
if (actionToLoad?.load) {
const filePath = actionToLoad.getFilePath
? actionToLoad.getFilePath(action)
? actionToLoad.getFilePath(dispatchedAction)
: undefined; // eslint-disable-line no-undefined
const content = loadAction(actionToLoad.success, filePath);

// persisted data not found -> dispatch original error action
if (!content) {
return next(dispatchedAction);
}

// if we load the action directly the content is already the complete action
// if we load content from a downloaded package we have to create the action
// object first with the successActionCreator function
const loadedAction = action.successActionCreator
? action.successActionCreator(action, content)
const loadedAction = actionToLoad.successActionCreator
? actionToLoad.successActionCreator(dispatchedAction, content)
: content;

if (loadedAction) {
Expand All @@ -101,5 +106,5 @@ export const offlineLoadMiddleware: Middleware = () => (
}

// return the original error action when not found
return next(action);
return next(dispatchedAction);
};