diff options
author | Matt Strapp <matt@mattstrapp.net> | 2023-10-20 18:08:15 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2023-10-20 18:08:15 -0500 |
commit | 472c18a99851397939351dd4cfc50220c84dc4c2 (patch) | |
tree | 1fecdab0268a6734fa2c6c6a9551bf1ea06ff1ed /clients/www/src/lib | |
download | zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.tar zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.tar.gz zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.tar.bz2 zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.tar.lz zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.tar.xz zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.tar.zst zorascript-472c18a99851397939351dd4cfc50220c84dc4c2.zip |
Initial skeleton (hehe) commit
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to '')
-rw-r--r-- | clients/www/src/lib/offlineToast.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/clients/www/src/lib/offlineToast.ts b/clients/www/src/lib/offlineToast.ts new file mode 100644 index 0000000..3ae943e --- /dev/null +++ b/clients/www/src/lib/offlineToast.ts @@ -0,0 +1,33 @@ +import { getToastStore, type ToastSettings } from '@skeletonlabs/skeleton'; + +const toastStore = getToastStore(); + +const offline: ToastSettings = { + message: 'You are currently offline.', + background: 'variant-filled-error', + autohide: false +}; + +const online: ToastSettings = { + message: 'You are back online.', + background: 'variant-filled-success', + autohide: true, + timeout: 3000 +}; + +/** + * Make a toast for if the PWA is ever brought offline for whatever reason. + */ +export default function offlineToast() { + window.addEventListener('offline', () => { + toastStore.clear(); + toastStore.trigger(offline); + }); + + window.addEventListener('online', () => { + toastStore.clear(); + setTimeout(() => { + toastStore.trigger(online); + }, 300); + }); +} |