From 30cff681e5871de8be2e2bf7ee07c7973cfcc049 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Fri, 11 Mar 2022 14:19:56 +0200 Subject: [PATCH 1/4] fix: wrong page is displayed after refresh --- .../layout/UpdateRefreshContainer.js | 21 ------------------- src/components/layout/index.js | 1 - src/store/actions/socket.js | 3 ++- 3 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 src/components/layout/UpdateRefreshContainer.js diff --git a/src/components/layout/UpdateRefreshContainer.js b/src/components/layout/UpdateRefreshContainer.js deleted file mode 100644 index c12c408c..00000000 --- a/src/components/layout/UpdateRefreshContainer.js +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; -import { Alert, NotificationCard } from '..'; - -const UpdateRefreshContainer = ({ onRefresh, onClose }) => { - return ( - - - - ); -}; - -export { UpdateRefreshContainer }; diff --git a/src/components/layout/index.js b/src/components/layout/index.js index d18babb4..991031a6 100644 --- a/src/components/layout/index.js +++ b/src/components/layout/index.js @@ -6,4 +6,3 @@ export * from './TabPanel'; export * from './Tabs'; export * from './FormContainers'; export * from './SocketStatusContainer'; -export * from './UpdateRefreshContainer'; diff --git a/src/store/actions/socket.js b/src/store/actions/socket.js index a0c46f5e..47b69cf6 100644 --- a/src/store/actions/socket.js +++ b/src/store/actions/socket.js @@ -27,9 +27,10 @@ let interval; const notifyRefresh = _.debounce(() => { NotificationManager.info( 'Click Here To Refresh.', - 'The data that is viewed may be out of date, and a refresh is reccomended', + 'The data that is viewed may be out of date, and a refresh is recommended', 20000, () => { + alert('refresh started'); saveCurrentUrlToStorage(); reloadApp(); }, From 256ffd1ad884f8b37993fdcced717d74826ea0a3 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Fri, 11 Mar 2022 15:49:21 +0200 Subject: [PATCH 2/4] fix: wrong page is displayed after refresh --- src/navigation/AppNavigator.js | 7 ++----- src/navigation/history.js | 20 -------------------- src/navigation/index.js | 1 - src/store/actions/socket.js | 7 +------ 4 files changed, 3 insertions(+), 32 deletions(-) delete mode 100644 src/navigation/history.js diff --git a/src/navigation/AppNavigator.js b/src/navigation/AppNavigator.js index b897519e..7dc68509 100644 --- a/src/navigation/AppNavigator.js +++ b/src/navigation/AppNavigator.js @@ -5,8 +5,9 @@ import { Router } from 'react-router'; import { Route, Redirect } from 'react-router-dom'; import { IndeterminateProgressOverlay, Dashboard } from '../components/'; import { NotificationContainer } from 'react-notifications'; +import { createBrowserHistory } from 'history'; +let history = createBrowserHistory(); -import { history, reloadCurrentUrlFromStorage } from './'; import { signOut } from '../store/actions/app'; import * as Pages from '../pages'; @@ -26,10 +27,6 @@ const AppNavigator = () => { const intl = useIntl(); const dispatch = useDispatch(); - useEffect(() => { - reloadCurrentUrlFromStorage(); - }, []); - const { showProgressOverlay, connectionCheck, diff --git a/src/navigation/history.js b/src/navigation/history.js deleted file mode 100644 index 5dd3db0c..00000000 --- a/src/navigation/history.js +++ /dev/null @@ -1,20 +0,0 @@ -import { createBrowserHistory } from 'history'; - -const history = createBrowserHistory(); - -const saveCurrentUrlToStorage = () => { - if (history.location?.pathname) { - const currentUrl = `${history.location.pathname}${history.location.search}&reload=true`; - localStorage.setItem('currentUrl', currentUrl); - } -}; - -const reloadCurrentUrlFromStorage = () => { - const currentUrl = localStorage.getItem('currentUrl'); - if (currentUrl) { - history.push(currentUrl); - localStorage.removeItem('currentUrl'); - } -}; - -export { history, saveCurrentUrlToStorage, reloadCurrentUrlFromStorage }; diff --git a/src/navigation/index.js b/src/navigation/index.js index 588aaf2a..44547fef 100644 --- a/src/navigation/index.js +++ b/src/navigation/index.js @@ -1,2 +1 @@ export * from './AppNavigator'; -export * from './history'; diff --git a/src/store/actions/socket.js b/src/store/actions/socket.js index 4736e029..87182805 100644 --- a/src/store/actions/socket.js +++ b/src/store/actions/socket.js @@ -3,7 +3,6 @@ import socketIO from 'socket.io-client'; import { messageTypes } from '../../utils/message-types'; import { keyMirror } from '../store-functions'; import { getStagingData } from './climateWarehouseActions'; -import { saveCurrentUrlToStorage } from '../../navigation/history'; import { refreshApp } from './app'; import { NotificationManager } from 'react-notifications'; import constants from '../../constants'; @@ -30,11 +29,7 @@ const notifyRefresh = _.debounce(dispatch => { 'Click Here To Refresh.', 'The data that is viewed may be out of date, and a refresh is recommended', 20000, - () => { - alert('refresh started'); - saveCurrentUrlToStorage(); - dispatch(refreshApp()); - }, + () => dispatch(refreshApp()), true, ); }, 5000); From 10b1d287c7567c38c91a3303c1777beb39c6c917 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Fri, 11 Mar 2022 18:16:51 +0200 Subject: [PATCH 3/4] fix: wrong page is displayed after refresh --- src/components/blocks/LeftNav.js | 35 ++++++++++---------------------- src/index.js | 2 ++ src/navigation/AppNavigator.js | 9 +++++--- src/navigation/history.js | 20 ++++++++++++++++++ src/navigation/index.js | 1 + src/store/actions/socket.js | 2 +- 6 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 src/navigation/history.js diff --git a/src/components/blocks/LeftNav.js b/src/components/blocks/LeftNav.js index 0fb12c38..7d095738 100644 --- a/src/components/blocks/LeftNav.js +++ b/src/components/blocks/LeftNav.js @@ -71,7 +71,6 @@ const StyledTitleContainer = styled('div')` `; const LeftNav = withTheme(({ children }) => { - const [location, setLocation] = useState(false); const [confirmCreateOrgIsVisible, setConfirmCreateOrgIsVisible] = useState(false); const [createOrgIsVisible, setCreateOrgIsVisible] = useState(false); @@ -95,9 +94,9 @@ const LeftNav = withTheme(({ children }) => { return () => clearTimeout(intervalId); }, [myOrgIsNotCreated, myOrgIsCreatedButNotSubscribed, createOrgIsVisible]); - useEffect(() => { - setLocation(window.location.pathname.split(/_(.+)/)[1]); - }, [window.location]); + const isUnitsPage = window.location.pathname.includes('/units'); + const isProjectsPage = window.location.pathname.includes('/projects'); + const isMyRegistryPage = window.location.search.includes('myRegistry=true'); return ( @@ -109,23 +108,17 @@ const LeftNav = withTheme(({ children }) => { { - dispatch(resetRefreshPrompt); - setLocation('projects'); - }} + onClick={() => dispatch(resetRefreshPrompt)} >
{ - dispatch(resetRefreshPrompt); - setLocation('units'); - }} + onClick={() => dispatch(resetRefreshPrompt)} > @@ -140,23 +133,17 @@ const LeftNav = withTheme(({ children }) => { {!myOrgIsNotCreated && !myOrgIsCreatedButNotSubscribed && ( <> { - dispatch(resetRefreshPrompt); - setLocation('my-projects'); - }} + onClick={() => dispatch(resetRefreshPrompt)} >
{ - dispatch(resetRefreshPrompt); - setLocation('my-units'); - }} + onClick={() => dispatch(resetRefreshPrompt)} > diff --git a/src/index.js b/src/index.js index de3008cd..40258c97 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import './index.css'; import App from './App'; import store from './store'; +import { saveCurrentUrlToStorage } from './navigation'; // Allows the app to reload in a platform agnostic way (either in browser or electron) const RefreshWrapper = () => { @@ -20,6 +21,7 @@ const RefreshWrapper = () => { }, [appStore.refresh]); if (appStore.refresh) { + saveCurrentUrlToStorage(); return null; } diff --git a/src/navigation/AppNavigator.js b/src/navigation/AppNavigator.js index 7dc68509..cf88003f 100644 --- a/src/navigation/AppNavigator.js +++ b/src/navigation/AppNavigator.js @@ -5,11 +5,9 @@ import { Router } from 'react-router'; import { Route, Redirect } from 'react-router-dom'; import { IndeterminateProgressOverlay, Dashboard } from '../components/'; import { NotificationContainer } from 'react-notifications'; -import { createBrowserHistory } from 'history'; -let history = createBrowserHistory(); import { signOut } from '../store/actions/app'; - +import { history } from './'; import * as Pages from '../pages'; import { createNotification } from '../utils/notificationUtils'; @@ -22,11 +20,16 @@ import { } from '../components'; import { setPendingError, setNotificationMessage } from '../store/actions/app'; import { getOrganizationData } from '../store/actions/climateWarehouseActions'; +import { reloadCurrentUrlFromStorage } from './history'; const AppNavigator = () => { const intl = useIntl(); const dispatch = useDispatch(); + useEffect(() => { + reloadCurrentUrlFromStorage(); + }, []); + const { showProgressOverlay, connectionCheck, diff --git a/src/navigation/history.js b/src/navigation/history.js new file mode 100644 index 00000000..5dd3db0c --- /dev/null +++ b/src/navigation/history.js @@ -0,0 +1,20 @@ +import { createBrowserHistory } from 'history'; + +const history = createBrowserHistory(); + +const saveCurrentUrlToStorage = () => { + if (history.location?.pathname) { + const currentUrl = `${history.location.pathname}${history.location.search}&reload=true`; + localStorage.setItem('currentUrl', currentUrl); + } +}; + +const reloadCurrentUrlFromStorage = () => { + const currentUrl = localStorage.getItem('currentUrl'); + if (currentUrl) { + history.push(currentUrl); + localStorage.removeItem('currentUrl'); + } +}; + +export { history, saveCurrentUrlToStorage, reloadCurrentUrlFromStorage }; diff --git a/src/navigation/index.js b/src/navigation/index.js index 44547fef..588aaf2a 100644 --- a/src/navigation/index.js +++ b/src/navigation/index.js @@ -1 +1,2 @@ export * from './AppNavigator'; +export * from './history'; diff --git a/src/store/actions/socket.js b/src/store/actions/socket.js index 87182805..2f11e269 100644 --- a/src/store/actions/socket.js +++ b/src/store/actions/socket.js @@ -29,7 +29,7 @@ const notifyRefresh = _.debounce(dispatch => { 'Click Here To Refresh.', 'The data that is viewed may be out of date, and a refresh is recommended', 20000, - () => dispatch(refreshApp()), + () => dispatch(refreshApp(true)), true, ); }, 5000); From ef403ce4df0d17b34029b283e90ad93ddbe9b388 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 11 Mar 2022 16:11:24 -0500 Subject: [PATCH 4/4] chore: bump to 0.1.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 541b0b7d..9d252d1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "climate-warehouse", - "version": "0.1.13", + "version": "0.1.14", "private": true, "author": "Chia Network Inc. ", "homepage": "./",