Skip to content

Commit

Permalink
fix(electron): fix persisted actions path (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwambach committed Mar 17, 2020
1 parent af069f9 commit 5531985
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
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);
};

0 comments on commit 5531985

Please sign in to comment.