Skip to content

Commit

Permalink
Merge pull request #688 from CrisisCleanup/tobi-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tabiodun authored Feb 7, 2024
2 parents 493dd99 + e610ee2 commit 47bed61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/hooks/incident/useCurrentIncident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/incident/useUserIncident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
Expand Down
4 changes: 4 additions & 0 deletions src/layouts/Authenticated.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export default defineComponent({
currentIncident,
currentIncidentId,
fetchIncidentDetails,
loadRecentIncident,
updateCurrentIncidentId,
} = useCurrentIncident();
const authStore = useAuthStore();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 47bed61

Please sign in to comment.