Add toast dinamically
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Alessio Davoli 2023-07-22 19:58:19 +02:00
parent 7d8f59dec7
commit 10fa4522ba

View file

@ -1,25 +1,30 @@
<script>
import BottomAppBar from '$lib/components/BottomAppBar.svelte';
import Toast from '$lib/components/Toast.svelte';
import { onMount } from 'svelte';
let node;
onMount(() => {
if ('serviceWorker' in navigator) {
addEventListener('load', function () {
navigator.serviceWorker.register('/service-worker.js');
});
navigator.serviceWorker.addEventListener('message', (event) => {
console.log(`The service worker sent me a message: ${event.data}`);
alert('You can use the app offline');
const channel = new BroadcastChannel('sw-messages');
channel.addEventListener('message', (event) => {
new Toast({ target: node });
});
navigator.serviceWorker.ready.then((registration) => {
console.log(registration);
console.log('registered service worker');
});
}
});
</script>
<div bind:this={node}></div>
<slot />
<footer>
<BottomAppBar />