Skip to content

Commit

Permalink
fix(dashboard): refresh too much
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Sep 26, 2023
1 parent 1ba5942 commit 0876991
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions dashboard/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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 (
<div className="main-container">
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0876991

Please sign in to comment.