diff options
Diffstat (limited to 'ui/routes')
| -rw-r--r-- | ui/routes/+layout.svelte | 88 |
1 files changed, 1 insertions, 87 deletions
diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte index 841d597..8412fbc 100644 --- a/ui/routes/+layout.svelte +++ b/ui/routes/+layout.svelte @@ -1,87 +1,10 @@ <script> - import { setContext, onMount } from "svelte"; + import { setContext } from "svelte"; import { onNavigate } from '$app/navigation'; import { page } from '$app/state'; import '../app.css'; import logo from '$lib/assets/logo.png'; - /* ==================== Start subscription library-esque ==================== */ - let subscriptionJson = $state(null); - - function doSubscribe() { - navigator.serviceWorker.ready - .then(async (registration) => { - const response = await fetch("/api/vapid"); - // and if we fail to get it? - const vapidPublicKey = await response.text(); - const convertedVapidKey = vapidPublicKey; - return registration.pushManager.subscribe({ - userVisibleOnly: true, - applicationServerKey: convertedVapidKey - }); - }).then((subscription) => { - const subJson = subscription.toJSON(); - subscriptionJson = { - endpoint: subJson.endpoint, - p256dh: subJson.keys.p256dh, - auth: subJson.keys.auth, - }; - return fetch("/api/push", { - method: "post", - headers: { "Content-type": "application/json" }, - body: JSON.stringify(subscriptionJson), - }); - }); - } - - async function doUnsubscribe() { - navigator.serviceWorker.ready - .then((registration) => { - return registration.pushManager.getSubscription(); - }).then((subscription) => { - const { endpoint } = subscription.toJSON(); - return subscription.unsubscribe() - .then(() => { - fetch("/api/push", { - method: "delete", - headers: { "Content-type": "application/json" }, - body: JSON.stringify({ endpoint }), - }); - subscriptionJson = null; - }); - }); - } - - function toggleSub() { - if (subscriptionJson !== null) { - doUnsubscribe(); - } else { - doSubscribe(); - } - } - - function notifyMe() { - fetch("/api/echo", { - method: "post", - headers: { "Content-type": "application/json" }, - body: JSON.stringify({ - endpoint: subscriptionJson.endpoint, - msg: JSON.stringify({"msg": "oople doople"}), - }) - }); - } - - onMount(() => { - navigator.serviceWorker.ready.then((registration) => { - return registration.pushManager.getSubscription(); - }).then((subscription) => { - if (subscription) { - subscriptionJson = JSON.parse(JSON.stringify(subscription)); - } - }); - }); - /* ==================== END ==================== */ - const session = $derived(page.data.session); let pageContext = $state({ showMenu: false, @@ -107,15 +30,6 @@ </button> </div> <a href="/">pilcrow</a> - <button onclick="{notifyMe}"> - notify - </button> - <button onclick="{toggleSub}"> - toggle sub - </button> - <div> - hasSub: {subscriptionJson !== null} - </div> <div class="trail"> {#if session} <div> |
