Skip to content

Commit

Permalink
fix: build refresh doesnt actually do anything anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Mar 1, 2022
1 parent 277da46 commit 8282faa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/navigation/AppNavigator.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -21,6 +26,10 @@ const AppNavigator = () => {
const intl = useIntl();
const dispatch = useDispatch();

useEffect(() => {
reloadCurrentUrlFromStorage();
}, []);

const {
showProgressOverlay,
connectionCheck,
Expand All @@ -32,7 +41,10 @@ const AppNavigator = () => {
<AppContainer>
{updateAvailablePleaseRefesh && (
<UpdateRefreshContainer
onRefresh={() => window.location.reload()}
onRefresh={() => {
saveCurrentUrlToStorage();
reloadApp();
}}
onClose={() => dispatch(resetRefreshPrompt)}
/>
)}
Expand Down
20 changes: 17 additions & 3 deletions src/navigation/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 8282faa

Please sign in to comment.