Skip to content

Commit

Permalink
Profile fetching failure toast (#1108)
Browse files Browse the repository at this point in the history
* Toast safety

* Show failure toast if resource or external resource queries fail

* Make sure external resource loading indicator is reset properly

* Make toasts test safe

---------

Co-authored-by: Dan Delany <dan.delany@gmail.com>
  • Loading branch information
2 people authored and JosephVolosin committed Oct 21, 2024
1 parent d7de7d7 commit 785fa62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
externalResourceNames,
externalResources,
fetchingResources,
fetchingResourcesExternal,
resetSimulationStores,
resourceTypes,
resources,
Expand Down Expand Up @@ -341,6 +342,7 @@
} else {
simulationDataAbortController?.abort();
fetchingResources.set(false);
fetchingResourcesExternal.set(false);
$resources = [];
$spans = [];
}
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,7 @@ const effects = {
const error = e as Error;
if (error.name !== 'AbortError') {
catchError(error);
showFailureToast('Failed to fetch profiles');
fetchingResources.set(false);
}
return [];
Expand Down Expand Up @@ -2935,6 +2936,7 @@ const effects = {
const error = e as Error;
if (error.name !== 'AbortError') {
catchError(error);
showFailureToast('Failed to fetch external profiles');
fetchingResourcesExternal.set(false);
}
return [];
Expand Down
9 changes: 9 additions & 0 deletions src/utilities/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function findToast(toastText: string, checkIsClosed: boolean = false) {
}

function hideToast(toast: Toast) {
// Only hide toast if in browser context
if (typeof document === 'undefined') {
return;
}

toast.options.close = true;
toast.hideToast();
}
Expand All @@ -35,6 +40,10 @@ function toastCallback(this: Element) {
}

function showToast(toast: Toast) {
// Only show toast if in browser context
if (typeof document === 'undefined') {
return;
}
const toastText = toast.options.text;
const existingToastIndex = toastText !== undefined ? findToast(toastText, true) : -1;

Expand Down

0 comments on commit 785fa62

Please sign in to comment.