From 7d8f59dec7e003130d927a9e15d0d0c5fd43cd3e Mon Sep 17 00:00:00 2001 From: Alessio Davoli Date: Sat, 22 Jul 2023 19:57:47 +0200 Subject: [PATCH] update sw.ts and toast component --- frontend/src/lib/components/Toast.svelte | 14 ++++++-------- frontend/src/sw.ts | 5 ++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/components/Toast.svelte b/frontend/src/lib/components/Toast.svelte index 994af44..724d4bc 100644 --- a/frontend/src/lib/components/Toast.svelte +++ b/frontend/src/lib/components/Toast.svelte @@ -5,17 +5,15 @@ let nodeRef; onMount(() => { - show = true; setTimeout(() => { - show = false; + show = true; setTimeout(() => { - nodeRef.parentNode.removeChild(nodeRef); + show = false; + setTimeout(() => { + nodeRef.parentNode.removeChild(nodeRef); + }, 5000); }, 5000); - }, 5000); - }); - - onDestroy(() => { - show = false; + }, 0); }); diff --git a/frontend/src/sw.ts b/frontend/src/sw.ts index 7f2965c..e873ab8 100644 --- a/frontend/src/sw.ts +++ b/frontend/src/sw.ts @@ -24,6 +24,9 @@ self.addEventListener('install', (event) => { event.waitUntil(addFilesToCache()); }); +const channel = new BroadcastChannel('sw-messages'); + + self.addEventListener('activate', (event) => { // Remove previous cached data from disk async function deleteOldCaches() { @@ -33,7 +36,7 @@ self.addEventListener('activate', (event) => { } event.waitUntil(deleteOldCaches()); - postMessage("completed"); + channel.postMessage({title: 'Cache downloaded!'}); }); self.addEventListener('fetch', (event) => {