Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): refresh too much #1673

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading