Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Oct 2, 2023
1 parent 798c150 commit 54cb65c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
22 changes: 4 additions & 18 deletions dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export default function DataLoader() {
const shouldStop = progress !== null && total !== null && isLoading;

if (shouldStart) {
console.log('START FUCKING SHIT initialLoad', initialLoad);
Promise.resolve()
.then(async () => {
/*
Expand All @@ -123,18 +122,6 @@ export default function DataLoader() {
.then(() => (initialLoad ? migrateData() : Promise.resolve()))
.then(() => getCacheItem(dashboardCurrentCacheKey))
.then((lastLoadValue) => {
console.log('lastLoadValue', lastLoadValue);
console.log('initialLoad', initialLoad);
console.log({
path: '/organisation/stats',
query: {
organisation: organisationId,
after: lastLoadValue || 0,
withDeleted: true,
// Medical data is never saved in cache so we always have to download all at every page reload.
withAllMedicalData: initialLoad,
},
});
setLastLoad(lastLoadValue || 0);
API.get({
path: '/organisation/stats',
Expand All @@ -146,7 +133,6 @@ export default function DataLoader() {
withAllMedicalData: initialLoad,
},
}).then(({ data: stats }) => {
console.log('REFRESH stats', stats);
if (!stats) return;
const newList = [];
let itemsCount =
Expand Down Expand Up @@ -407,7 +393,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('resetLoaderOnError');
await clearCache();
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 +551,7 @@ export default function DataLoader() {
.then(async () => {
console.log('cacheIsInvalidated', cacheIsInvalidated);
if (cacheIsInvalidated) {
await clearCache('cacheIsInvalidated').then(() => {
await clearCache().then(() => {
// startInitialLoad
setLastLoad(0);
setIsLoading(true);
Expand Down Expand Up @@ -639,8 +625,8 @@ export function useDataLoader(options = { refreshOnMount: false }) {
setLoadingText('Chargement des données');
}

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

Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/components/ReceptionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ 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('reset cache from different organisation');
await resetCache();
}
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('reset cache from different organisation too');
await resetCache();
}
window.localStorage.setItem('mano-organisationId', organisation._id);
setOrganisation(organisation);
Expand Down
3 changes: 1 addition & 2 deletions dashboard/src/services/dataManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ async function getManoCacheStorage() {
return manoCacheStorage;
}

export async function clearCache(calledFrom) {
console.log('clearCache called from', calledFrom);
export async function clearCache() {
(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 54cb65c

Please sign in to comment.