2025-09-09 16:54:08 +00:00
|
|
|
<script lang="ts">
|
2026-01-20 18:40:33 +00:00
|
|
|
import cx from "classnames"
|
2026-02-02 17:51:36 +00:00
|
|
|
import {sleep} from "@welshman/lib"
|
2026-01-22 22:23:46 +00:00
|
|
|
import {Capacitor} from "@capacitor/core"
|
|
|
|
|
import {Badge} from "@capawesome/capacitor-badge"
|
2026-03-11 22:48:36 +00:00
|
|
|
import Bell from "@assets/icons/bell.svg?dataurl"
|
2026-01-20 00:33:16 +00:00
|
|
|
import {preventDefault} from "@lib/html"
|
2026-04-17 21:58:52 +00:00
|
|
|
import FieldInline from "@lib/components/FieldInline.svelte"
|
2026-07-15 16:30:17 +00:00
|
|
|
import ToggleInput from "@lib/components/ToggleInput.svelte"
|
2026-01-24 00:51:02 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2026-03-11 22:48:36 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-01-20 00:33:16 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-06-24 20:56:53 +00:00
|
|
|
import PageContent from "@lib/components/PageContent.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
|
|
|
|
import {clearBadges} from "@app/notifications"
|
|
|
|
|
import {Push} from "@app/push"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {notificationSettings} from "@app/settings"
|
2026-01-20 00:33:16 +00:00
|
|
|
|
|
|
|
|
const reset = () => {
|
2026-01-24 00:51:02 +00:00
|
|
|
settings = {...notificationSettings.get()}
|
2026-01-20 00:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-24 00:51:02 +00:00
|
|
|
const onsubmit = preventDefault(async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (!settings.badge) {
|
|
|
|
|
clearBadges()
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 15:32:32 +00:00
|
|
|
let permission = "granted"
|
|
|
|
|
|
2026-01-24 00:51:02 +00:00
|
|
|
if (settings.push) {
|
2026-03-19 15:32:32 +00:00
|
|
|
permission = await Push.request()
|
2026-01-24 00:51:02 +00:00
|
|
|
|
2026-03-19 15:32:32 +00:00
|
|
|
if (!permission.startsWith("granted")) {
|
2026-01-24 00:51:02 +00:00
|
|
|
await sleep(300)
|
2026-01-20 18:40:33 +00:00
|
|
|
|
2026-01-24 00:51:02 +00:00
|
|
|
settings.push = false
|
|
|
|
|
|
2026-01-28 01:15:22 +00:00
|
|
|
return pushToast({
|
2026-01-24 00:51:02 +00:00
|
|
|
theme: "error",
|
2026-03-19 15:32:32 +00:00
|
|
|
message: `Failed to request notification permissions (${permission}).`,
|
2026-01-20 18:40:33 +00:00
|
|
|
})
|
|
|
|
|
}
|
2026-01-24 00:51:02 +00:00
|
|
|
}
|
2026-01-22 20:37:30 +00:00
|
|
|
|
2026-01-24 00:51:02 +00:00
|
|
|
notificationSettings.set(settings)
|
2026-01-23 23:35:54 +00:00
|
|
|
|
2026-01-24 00:51:02 +00:00
|
|
|
pushToast({message: "Your settings have been saved!"})
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
2026-01-20 00:33:16 +00:00
|
|
|
})
|
|
|
|
|
|
2026-01-24 00:51:02 +00:00
|
|
|
let loading = $state(false)
|
|
|
|
|
let settings = $state({...notificationSettings.get()})
|
2025-09-09 16:54:08 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-06-24 20:56:53 +00:00
|
|
|
<form {onsubmit}>
|
|
|
|
|
<PageContent>
|
|
|
|
|
<div class="card flex flex-col gap-4 shadow-md">
|
|
|
|
|
<strong class="flex items-center gap-3 text-lg">
|
|
|
|
|
<Icon icon={Bell} />
|
|
|
|
|
Alert Settings
|
|
|
|
|
</strong>
|
|
|
|
|
{#await Badge.isSupported()}
|
|
|
|
|
<!-- pass -->
|
|
|
|
|
{:then { isSupported }}
|
|
|
|
|
{#if isSupported}
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Show badge for unread alerts</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<ToggleInput bind:checked={settings.badge} />
|
2026-06-24 20:56:53 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
{/if}
|
|
|
|
|
{/await}
|
|
|
|
|
{#if !Capacitor.isNativePlatform()}
|
2026-04-17 21:58:52 +00:00
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<p>Play sound for new activity</p>
|
2026-04-17 21:58:52 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<ToggleInput bind:checked={settings.sound} />
|
2026-04-17 21:58:52 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
2026-01-22 22:23:46 +00:00
|
|
|
{/if}
|
2026-04-17 21:58:52 +00:00
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<p>Enable push notifications</p>
|
2026-04-17 21:58:52 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<ToggleInput bind:checked={settings.push} />
|
2026-04-17 21:58:52 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
2026-06-24 20:56:53 +00:00
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class={cx("card bg-surface flex flex-col gap-4 shadow-md", {
|
|
|
|
|
"pointer-events-none opacity-50": !settings.badge && !settings.sound && !settings.push,
|
|
|
|
|
})}>
|
|
|
|
|
<strong class="text-lg">Alert Types</strong>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Notify me about new activity</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<ToggleInput bind:checked={settings.spaces} />
|
2026-06-24 20:56:53 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Always notify me when mentioned</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-27 22:21:39 +00:00
|
|
|
<ToggleInput bind:checked={settings.mentions} />
|
2026-06-24 20:56:53 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
<FieldInline>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Notify me about new messages</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-15 16:30:17 +00:00
|
|
|
<ToggleInput bind:checked={settings.messages} />
|
2026-06-24 20:56:53 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</FieldInline>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card sticky -bottom-3 shadow-md flex flex-row items-center justify-between gap-4">
|
|
|
|
|
<Button class="button button-neutral" onclick={reset} disabled={loading}
|
|
|
|
|
>Discard Changes</Button>
|
|
|
|
|
<Button type="submit" class="button button-primary" disabled={loading}>
|
|
|
|
|
<Spinner {loading}>Save Changes</Spinner>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</PageContent>
|
2026-01-20 00:33:16 +00:00
|
|
|
</form>
|