From 8282faa8f0261b92ec8ca07fd2e063c9894d9876 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Tue, 1 Mar 2022 10:52:43 +0200 Subject: [PATCH] fix: build refresh doesnt actually do anything anymore --- src/navigation/AppNavigator.js | 18 +++++++++++++++--- src/navigation/history.js | 20 +++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/navigation/AppNavigator.js b/src/navigation/AppNavigator.js index 307e1367..7d9eefd8 100644 --- a/src/navigation/AppNavigator.js +++ b/src/navigation/AppNavigator.js @@ -1,11 +1,16 @@ -import React, { Suspense } from 'react'; +import React, { Suspense, useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { useIntl } from 'react-intl'; import { Router } from 'react-router'; import { Route } from 'react-router-dom'; import { IndeterminateProgressOverlay, Dashboard } from '../components/'; import { resetRefreshPrompt } from '../store/actions/app'; -import { history, reloadApp } from './'; +import { + history, + reloadApp, + saveCurrentUrlToStorage, + reloadCurrentUrlFromStorage, +} from './'; import * as Pages from '../pages'; import { @@ -21,6 +26,10 @@ const AppNavigator = () => { const intl = useIntl(); const dispatch = useDispatch(); + useEffect(() => { + reloadCurrentUrlFromStorage(); + }, []); + const { showProgressOverlay, connectionCheck, @@ -32,7 +41,10 @@ const AppNavigator = () => { {updateAvailablePleaseRefesh && ( window.location.reload()} + onRefresh={() => { + saveCurrentUrlToStorage(); + reloadApp(); + }} onClose={() => dispatch(resetRefreshPrompt)} /> )} diff --git a/src/navigation/history.js b/src/navigation/history.js index 2fa6a36d..64be4601 100644 --- a/src/navigation/history.js +++ b/src/navigation/history.js @@ -6,10 +6,24 @@ const reloadApp = () => { history.push('/'); }; -const reloadCurrentUrl = () => { +const saveCurrentUrlToStorage = () => { if (history?.location?.pathname) { - history.push(`${history.location.pathname}${history.location.search}`); + const currentUrl = `${history.location.pathname}${history.location.search}&reload=true`; + localStorage.setItem('currentUrl', currentUrl); } }; -export { history, reloadApp, reloadCurrentUrl }; +const reloadCurrentUrlFromStorage = () => { + const currentUrl = localStorage.getItem('currentUrl'); + if (currentUrl) { + history.push(currentUrl); + localStorage.removeItem('currentUrl'); + } +}; + +export { + history, + reloadApp, + saveCurrentUrlToStorage, + reloadCurrentUrlFromStorage, +};