From e610ee2af7d5fba77026f654dc7f0f22f8a1711b Mon Sep 17 00:00:00 2001 From: Tobi Abiodun Date: Wed, 7 Feb 2024 15:04:44 -0500 Subject: [PATCH] https://github.com/CrisisCleanup/crisiscleanup-4-web/issues/687 --- src/hooks/incident/useCurrentIncident.ts | 5 +++++ src/hooks/incident/useUserIncident.ts | 5 ++++- src/layouts/Authenticated.vue | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hooks/incident/useCurrentIncident.ts b/src/hooks/incident/useCurrentIncident.ts index af6a2e6dd..deeffbb36 100644 --- a/src/hooks/incident/useCurrentIncident.ts +++ b/src/hooks/incident/useCurrentIncident.ts @@ -127,12 +127,17 @@ export const useCurrentIncident = () => { : updateUserIncident(newIncidentId)); }; + const loadRecentIncident = async () => { + await recentIncidentState.execute().catch(getErrorMessage); + }; + return { currentIncidentId: readonly(currentIncidentId), currentIncident, hasCurrentIncident, isCurrentIncidentLoading, updateCurrentIncidentId, + loadRecentIncident, fetchIncidentDetails: async () => { debug('Fetching incident details...'); await fetchInstance().catch(getErrorMessage); diff --git a/src/hooks/incident/useUserIncident.ts b/src/hooks/incident/useUserIncident.ts index c7e586ac4..19143fc5d 100644 --- a/src/hooks/incident/useUserIncident.ts +++ b/src/hooks/incident/useUserIncident.ts @@ -56,7 +56,10 @@ export const useUserIncident = ( incidentStates: incidentFromStates.value, incidentId: incidentId.value, }); - await updateUserIncident(newValue).catch(getErrorMessage); + // update user states if new incident id is defined and does not match incident id from states. + if (newValue) { + await updateUserIncident(newValue).catch(getErrorMessage); + } }, { immediate: true }, ); diff --git a/src/layouts/Authenticated.vue b/src/layouts/Authenticated.vue index 112c14b5d..3dbcf20b5 100644 --- a/src/layouts/Authenticated.vue +++ b/src/layouts/Authenticated.vue @@ -208,6 +208,7 @@ export default defineComponent({ currentIncident, currentIncidentId, fetchIncidentDetails, + loadRecentIncident, updateCurrentIncidentId, } = useCurrentIncident(); const authStore = useAuthStore(); @@ -509,6 +510,9 @@ export default defineComponent({ // Load other page data (/incidents, /organizations, /languages, etc.) // It's because loading /incidents before loading current user incident is slow // Note: The sequence of operations here is crucial for achieving the desired performance. + if (!currentIncidentId.value) { + loadRecentIncident().catch(getErrorMessage); + } fetchIncidentDetails().catch(getErrorMessage); // Load all other page data after loading user incident loadState.execute().catch(getErrorMessage);