feat: add push notification support (#73)

* feat: add push notification support

* misc: set localstorage on start
This commit is contained in:
Xylight authored and GitHub committed 2023-08-06 13:00:35 -07:00
1 parent 4f898915b2
commit fc38560eda
6 files changed
+204 -24

No files matched your search

+23
View File
@@ -4,6 +4,9 @@
import Setting from './Setting.svelte'
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
import Sort from '$lib/components/lemmy/Sort.svelte'
import { toast } from '$lib/components/ui/toasts/toasts.js'
import Button from '$lib/components/input/Button.svelte'
import { getInboxNotifications } from '$lib/auth.js'
let data = {
loading: false,
@@ -91,4 +94,24 @@
</div>
</div>
</Setting>
<h2 class="uppercase font-bold opacity-80 text-sm mt-4">Notifications</h2>
<Setting>
<span slot="title">Push notifications</span>
<span slot="description">Get notified for new items in your inbox.</span>
<Switch
bind:enabled={$userSettings.notifications.enabled}
on:change={async (e) => {
if (e.detail == false) return
const res = await Notification.requestPermission()
if (res != 'granted') {
$userSettings.notifications.enabled = false
toast({
content: 'Notification permission denied',
type: 'error',
})
return
}
}}
/>
</Setting>
</div>