From de6c1ad727379c5ebe8550124ea9313979124953 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 19 Oct 2024 21:55:05 -0700 Subject: push notifications --- src/routes/(app)/locations/+server.ts | 17 ++--- src/routes/(app)/settings/[...tab]/+page.server.ts | 1 + src/routes/(app)/settings/[...tab]/_pos.svelte | 75 ++++++++++++++-------- src/routes/(app)/subscription/+server.ts | 7 +- src/routes/(app)/subscription/delete/+server.ts | 8 +++ src/routes/map/+page.server.ts | 12 ++-- src/routes/start/+server.ts | 10 +-- 7 files changed, 78 insertions(+), 52 deletions(-) create mode 100644 src/routes/(app)/subscription/delete/+server.ts (limited to 'src/routes') diff --git a/src/routes/(app)/locations/+server.ts b/src/routes/(app)/locations/+server.ts index 987459bc..f3fa1023 100644 --- a/src/routes/(app)/locations/+server.ts +++ b/src/routes/(app)/locations/+server.ts @@ -2,14 +2,15 @@ import { get } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function GET({ setHeaders }) { - let locations = []; + let locations = []; - try { - ({ locations } = await get("/locations")); - setHeaders({ "cache-control": "public, max-age=600" }); - } catch (e) { - console.log("failed to fetch locations"); - } + try { + ({ locations } = await get("/locations")); + console.log(locations); + setHeaders({ "cache-control": "public, max-age=600" }); + } catch (e) { + console.log("failed to fetch locations"); + } - return json({ locations }); + return json({ locations }); } diff --git a/src/routes/(app)/settings/[...tab]/+page.server.ts b/src/routes/(app)/settings/[...tab]/+page.server.ts index 42639b38..7c1542c0 100644 --- a/src/routes/(app)/settings/[...tab]/+page.server.ts +++ b/src/routes/(app)/settings/[...tab]/+page.server.ts @@ -14,6 +14,7 @@ export const actions = { if (form.tab === "pos") { form.notify = form.notify === "on"; + form.push = form.push === "on"; form.nip5 = form.nip5 === "on"; form.prompt = form.prompt === "on"; form.autowithdraw = form.autowithdraw === "on"; diff --git a/src/routes/(app)/settings/[...tab]/_pos.svelte b/src/routes/(app)/settings/[...tab]/_pos.svelte index 7ccaa69f..7ea76c53 100644 --- a/src/routes/(app)/settings/[...tab]/_pos.svelte +++ b/src/routes/(app)/settings/[...tab]/_pos.svelte @@ -1,12 +1,14 @@
@@ -105,15 +120,19 @@
{$t("user.settings.pushNotifications")} - + {#if permission !== "denied"} + + {/if}

- {$t("user.settings.pushNotificationsDesc")} + {#if permission === "denied"} + {$t("user.settings.pushNotificationsDisabled")} + {:else} + {$t("user.settings.pushNotificationsDesc")} + {/if}

-{JSON.stringify(subscription)} -
{$t("user.settings.tipPrompt")} diff --git a/src/routes/(app)/subscription/+server.ts b/src/routes/(app)/subscription/+server.ts index 8ae3f965..47dfc770 100644 --- a/src/routes/(app)/subscription/+server.ts +++ b/src/routes/(app)/subscription/+server.ts @@ -2,10 +2,7 @@ import { auth, post } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const result = await post( - "/subscription", - await request.json(), - auth(cookies), - ); + const body = await request.json(); + const result = await post("/subscription", body, auth(cookies)); return json(result); } diff --git a/src/routes/(app)/subscription/delete/+server.ts b/src/routes/(app)/subscription/delete/+server.ts new file mode 100644 index 00000000..f4c8357c --- /dev/null +++ b/src/routes/(app)/subscription/delete/+server.ts @@ -0,0 +1,8 @@ +import { auth, post } from "$lib/utils"; +import { json } from "@sveltejs/kit"; + +export async function POST({ cookies, request }) { + const body = await request.json(); + const result = await post("/subscription/delete", body, auth(cookies)); + return json(result); +} diff --git a/src/routes/map/+page.server.ts b/src/routes/map/+page.server.ts index 5012e7e3..b921cc22 100644 --- a/src/routes/map/+page.server.ts +++ b/src/routes/map/+page.server.ts @@ -1,11 +1,11 @@ import { get } from "$lib/utils"; -export let load = async () => { - let data = { locations: [] }; +export const load = async () => { + let data = { locations: [] }; - try { - data = await get("/locations"); - } catch (e) {} + try { + data = await get("/locations"); + } catch (e) {} - return data; + return data; }; diff --git a/src/routes/start/+server.ts b/src/routes/start/+server.ts index 2a1d88c3..58bca85f 100644 --- a/src/routes/start/+server.ts +++ b/src/routes/start/+server.ts @@ -1,10 +1,10 @@ import { redirect } from "@sveltejs/kit"; export async function GET({ cookies }) { - let username = cookies.get("username"); - if (username) { - redirect(307, `/invoice`); - } + const username = cookies.get("username"); + if (username) { + redirect(307, `/${username}/receive`); + } - redirect(307, "/"); + redirect(307, "/"); } -- cgit v1.2.3