Skip to content

Commit

Permalink
https://github.com/CrisisCleanup/crisiscleanup-4-web/issues/687
Browse files Browse the repository at this point in the history
  • Loading branch information
tabiodun committed Feb 7, 2024
1 parent b08710b commit e610ee2
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);
};

Check warning on line 132 in src/hooks/incident/useCurrentIncident.ts

View check run for this annotation

Codecov / codecov/patch

src/hooks/incident/useCurrentIncident.ts#L131-L132

Added lines #L131 - L132 were not covered by tests

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,

Check warning on line 211 in src/layouts/Authenticated.vue

View check run for this annotation

Codecov / codecov/patch

src/layouts/Authenticated.vue#L211

Added line #L211 was not covered by tests
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);
}

Check warning on line 515 in src/layouts/Authenticated.vue

View check run for this annotation

Codecov / codecov/patch

src/layouts/Authenticated.vue#L513-L515

Added lines #L513 - L515 were not covered by tests
fetchIncidentDetails().catch(getErrorMessage);
// Load all other page data after loading user incident
loadState.execute().catch(getErrorMessage);
Expand Down

0 comments on commit e610ee2

Please sign in to comment.