diff --git a/frontend/src/lib/components/ToastNotification.svelte b/frontend/src/lib/components/ToastNotification.svelte new file mode 100644 index 00000000..e7a1e6be --- /dev/null +++ b/frontend/src/lib/components/ToastNotification.svelte @@ -0,0 +1,11 @@ + + +{#if $showToast} +
+
+ {$toastMessage} +
+
+{/if} diff --git a/frontend/src/lib/stores/stores.ts b/frontend/src/lib/stores/stores.ts index b17e8eca..d6fccd27 100644 --- a/frontend/src/lib/stores/stores.ts +++ b/frontend/src/lib/stores/stores.ts @@ -48,3 +48,26 @@ export const isLoading = writable(false); isLoading.subscribe((value: boolean) => { return value; }); + +export const showToast = writable(false); + +showToast.subscribe((value: boolean) => { + return value; +}); + +export const toastMessage = writable(); + +toastMessage.subscribe((value: string) => { + return value; +}); + +function delay(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +export async function setToast(message: string, timeout = 5000) { + toastMessage.set(message); + showToast.set(true); + await delay(timeout); + showToast.set(false); +} diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 3c4c90ba..5c3e74db 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -1,11 +1,13 @@
+