diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-11-08 16:28:10 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-11-08 16:28:10 -0500 |
| commit | fc6914831743f6d683c59adb367479defe6f8b3a (patch) | |
| tree | 5b997adac55f47b52f30022013b8ec3b2c10bcc5 /ui/lib/components/PushSubscription.svelte | |
| parent | 0ef69c7d256380e660edc45ace7f1d6151226340 (diff) | |
| parent | 6bab5b4405c9adafb2ce76540595a62eea80acc0 (diff) | |
Integrate the prototype push notification support.
We're going to move forwards with this for now, as low-utility as it is, so that we can more easily iterate on it in a real-world environment (hi.grimoire.ca).
Diffstat (limited to 'ui/lib/components/PushSubscription.svelte')
| -rw-r--r-- | ui/lib/components/PushSubscription.svelte | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ui/lib/components/PushSubscription.svelte b/ui/lib/components/PushSubscription.svelte new file mode 100644 index 0000000..aab4929 --- /dev/null +++ b/ui/lib/components/PushSubscription.svelte @@ -0,0 +1,30 @@ +<script> + let { vapid, subscription, subscribe = async () => null, ping = async () => null } = $props(); + let pending = $state(false); + + function onsubmit(callback) { + return async (evt) => { + evt.preventDefault(); + + pending = true; + try { + await callback(); + } finally { + pending = false; + } + }; + } +</script> + +{#if !!vapid} + {#if !subscription} + <form class="form" onsubmit={onsubmit(subscribe)}> + <button disabled={pending} type="submit">create push subscription</button> + </form> + {/if} + <form class="form" onsubmit={onsubmit(ping)}> + <button disabled={pending} type="submit">send test notification</button> + </form> +{:else} + Waiting for VAPID key… +{/if} |
