Skip to content

Commit

Permalink
fix: order of initialLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Oct 2, 2023
1 parent d62919e commit 798c150
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default function DataLoader() {
async function resetLoaderOnError() {
// an error was thrown, the data was not downloaded,
// this can result in data corruption, we need to reset the loader
await clearCache();
await clearCache('resetLoaderOnError');
setLastLoad(0);
toast.error('Désolé, une erreur est survenue lors du chargement de vos données, veuillez réessayer', {
onClose: () => window.location.replace('/auth'),
Expand Down Expand Up @@ -565,7 +565,7 @@ export default function DataLoader() {
.then(async () => {
console.log('cacheIsInvalidated', cacheIsInvalidated);
if (cacheIsInvalidated) {
await clearCache().then(() => {
await clearCache('cacheIsInvalidated').then(() => {
// startInitialLoad
setLastLoad(0);
setIsLoading(true);
Expand Down Expand Up @@ -639,9 +639,9 @@ export function useDataLoader(options = { refreshOnMount: false }) {
setLoadingText('Chargement des données');
}

async function resetCache() {
async function resetCache(from) {
await clearCache('resetCache' + (from ? ` from ${from}` : ''));
setLastLoad(0);
await clearCache();
}

async function checkDataConsistency() {
Expand Down
2 changes: 0 additions & 2 deletions dashboard/src/components/ReceptionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ const ReceptionService = ({ report, team, dateString, dataTestIdPrefix = '', ser
useEffect(
// Init services for a team. We need to fetch services from legacy report and database and merge them.
function initServices() {
console.log('INIT SERVICE FROM ReceptionService ?');
if (!dateString || !team?._id || dateString === 'undefined') {
return capture('Missing params for initServices in reception', { extra: { dateString, team, report } });
}
console.log('INIT SERVICE FROM ReceptionService ');
API.get({ path: `/service/team/${team._id}/date/${dateString}` }).then((res) => {
if (!res.ok) return toast.error(<ErrorOnGetServices />);
const servicesFromLegacyReport = report?.services?.length ? JSON.parse(report?.services) : {};
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/scenes/auth/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const SignIn = () => {
setAuthViaCookie(true);
const { organisation } = user;
if (organisation._id !== window.localStorage.getItem('mano-organisationId')) {
await resetCache();
await resetCache('reset cache from different organisation');
}
window.localStorage.setItem('mano-organisationId', organisation._id);
setOrganisation(organisation);
Expand Down Expand Up @@ -112,7 +112,7 @@ const SignIn = () => {
if (token) setToken(token);
setSessionInitialTimestamp(Date.now());
if (organisation._id !== window.localStorage.getItem('mano-organisationId')) {
await resetCache();
await resetCache('reset cache from different organisation too');
}
window.localStorage.setItem('mano-organisationId', organisation._id);
setOrganisation(organisation);
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/services/dataManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ async function getManoCacheStorage() {
return manoCacheStorage;
}

export async function clearCache() {
export async function clearCache(calledFrom) {
console.log('clearCache called from', calledFrom);
(await getManoCacheStorage())?.clear();
manoCacheStorage = undefined; // needed so that the clean the all DB when required functions
window.localStorage?.clear();
Expand Down

0 comments on commit 798c150

Please sign in to comment.