From 330b733b046b729cba44b0e6e4c03d94139ce169 Mon Sep 17 00:00:00 2001 From: Arnaud Ambroselli <31724752+arnaudambro@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:16:40 +0200 Subject: [PATCH] fix(dashboard): refresh too much (#1673) --- dashboard/src/app.js | 15 ++++++++++++--- dashboard/src/components/DataLoader.js | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dashboard/src/app.js b/dashboard/src/app.js index 5cafa93a9..926c65d87 100644 --- a/dashboard/src/app.js +++ b/dashboard/src/app.js @@ -33,7 +33,7 @@ import ScrollToTop from './components/ScrollToTop'; import TopBar from './components/TopBar'; import VersionOutdatedAlert from './components/VersionOutdatedAlert'; import ModalConfirm from './components/ModalConfirm'; -import DataLoader, { useDataLoader } from './components/DataLoader'; +import DataLoader, { initialLoadingTextState, loadingTextState, useDataLoader } from './components/DataLoader'; import { Bounce, cssTransition, ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import SentryRoute from './components/Sentryroute'; @@ -90,6 +90,7 @@ if (ENV === 'production') { const App = ({ resetRecoil }) => { const authToken = useRecoilValue(authTokenState); const user = useRecoilValue(userState); + const loadingText = useRecoilValue(loadingTextState); const recoilResetKey = useRecoilValue(recoilResetKeyState); useEffect(() => { @@ -104,14 +105,22 @@ const App = ({ resetRecoil }) => { const onWindowFocus = (e) => { if (authToken && e.newState === 'active') { API.get({ path: '/check-auth' }) // will force logout if session is expired - .then(() => refresh()); // will refresh data if session is still valid + .then(() => { + if (loadingText !== initialLoadingTextState) { + // if the app is already loaded + // will refresh data if session is still valid + refresh(); + } else { + console.log('initial load not done'); + } + }); } }; lifecycle.addEventListener('statechange', onWindowFocus); return () => { lifecycle.removeEventListener('statechange', onWindowFocus); }; - }, [authToken, refresh]); + }, [authToken, refresh, loadingText]); return (
diff --git a/dashboard/src/components/DataLoader.js b/dashboard/src/components/DataLoader.js index 33daaa06b..b3a3b2d24 100644 --- a/dashboard/src/components/DataLoader.js +++ b/dashboard/src/components/DataLoader.js @@ -38,7 +38,8 @@ const isLoadingState = atom({ key: 'isLoadingState', default: false }); const initialLoadState = atom({ key: 'isInitialLoadState', default: false }); const fullScreenState = atom({ key: 'fullScreenState', default: true }); export const lastLoadState = atom({ key: 'lastLoadState', default: null, effects: [cacheEffect] }); -export const loadingTextState = atom({ key: 'loadingTextState', default: 'Chargement des données' }); +export const initialLoadingTextState = 'En attente de chargement'; +export const loadingTextState = atom({ key: 'loadingTextState', default: initialLoadingTextState }); export default function DataLoader() { const [user, setUser] = useRecoilState(userState); @@ -377,6 +378,7 @@ export default function DataLoader() { function stopLoader() { setIsLoading(false); setLastLoad(serverDate.current); + setLoadingText('En attente de chargement'); setProgressBuffer(null); setProgress(null); setTotal(null);