From 5531985bc6151e71f8775ee25809f2395d6adeb7 Mon Sep 17 00:00:00 2001 From: Philipp Wambach Date: Tue, 17 Mar 2020 15:28:53 +0100 Subject: [PATCH] fix(electron): fix persisted actions path (#295) --- src/electron/preload.js | 4 ++-- .../libs/electron/get-offline-tiles-url.ts | 1 + src/scripts/libs/electron/offline-middleware.ts | 17 +++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/electron/preload.js b/src/electron/preload.js index b38e5232c..ad02626df 100644 --- a/src/electron/preload.js +++ b/src/electron/preload.js @@ -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 diff --git a/src/scripts/libs/electron/get-offline-tiles-url.ts b/src/scripts/libs/electron/get-offline-tiles-url.ts index d80c411af..75c86467b 100644 --- a/src/scripts/libs/electron/get-offline-tiles-url.ts +++ b/src/scripts/libs/electron/get-offline-tiles-url.ts @@ -6,6 +6,7 @@ export function getOfflineTilesUrl(): string { } return window.cfs.getDownloadsPath( + 'downloads', '{id}', 'tiles', '{timeIndex}', diff --git a/src/scripts/libs/electron/offline-middleware.ts b/src/scripts/libs/electron/offline-middleware.ts index dbab166cb..462540b7f 100644 --- a/src/scripts/libs/electron/offline-middleware.ts +++ b/src/scripts/libs/electron/offline-middleware.ts @@ -74,9 +74,9 @@ export const offlineSaveMiddleware: Middleware = () => ( // dispatched export const offlineLoadMiddleware: Middleware = () => ( next: Dispatch -) => (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, @@ -84,15 +84,20 @@ export const offlineLoadMiddleware: Middleware = () => ( // 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) { @@ -101,5 +106,5 @@ export const offlineLoadMiddleware: Middleware = () => ( } // return the original error action when not found - return next(action); + return next(dispatchedAction); };