Add checkboxes for badge/sound settings

This commit is contained in:
Matthew Remmel
2025-09-23 10:25:11 -04:00
committed by hodlbod
parent d1c6f53d7c
commit 5cb22d0bed
2 changed files with 50 additions and 6 deletions

View File

@@ -10,7 +10,15 @@
import AlertItem from "@app/components/AlertItem.svelte" import AlertItem from "@app/components/AlertItem.svelte"
import {pushModal} from "@app/util/modal" import {pushModal} from "@app/util/modal"
import {pushToast} from "@app/util/toast" import {pushToast} from "@app/util/toast"
import {alerts, dmAlert, deriveAlertStatus, userInboxRelays, getAlertFeed} from "@app/core/state" import {
alerts,
dmAlert,
deriveAlertStatus,
userInboxRelays,
getAlertFeed,
showUnreadBadge,
playAlertSound,
} from "@app/core/state"
import {deleteAlert, createDmAlert} from "@app/core/commands" import {deleteAlert, createDmAlert} from "@app/core/commands"
type Props = { type Props = {
@@ -42,11 +50,11 @@
const uncheckDmAlert = async (message: string) => { const uncheckDmAlert = async (message: string) => {
await sleep(100) await sleep(100)
toggle.checked = false directMessagesNotificationToggle.checked = false
pushToast({theme: "error", message}) pushToast({theme: "error", message})
} }
const onToggle = async () => { const onDirectMessagesNotificationToggle = async () => {
if ($dmAlert) { if ($dmAlert) {
deleteAlert($dmAlert) deleteAlert($dmAlert)
} else { } else {
@@ -64,7 +72,15 @@
} }
} }
let toggle: HTMLInputElement const onShowBadgeOnUnreadToggle = async () => {
$showUnreadBadge = !$showUnreadBadge
}
const onDirectMessagesNotificationSoundToggle = async () => {
$playAlertSound = !$playAlertSound
}
let directMessagesNotificationToggle: HTMLInputElement
</script> </script>
<div class="col-4"> <div class="col-4">
@@ -93,9 +109,25 @@
<input <input
type="checkbox" type="checkbox"
class="toggle toggle-primary" class="toggle toggle-primary"
bind:this={toggle} bind:this={directMessagesNotificationToggle}
checked={Boolean($dmAlert)} checked={Boolean($dmAlert)}
oninput={onToggle} /> oninput={onDirectMessagesNotificationToggle} />
</div>
<div class="flex justify-between">
<p>Show badge for unread direct messages</p>
<input
type="checkbox"
class="toggle toggle-primary"
checked={Boolean($showUnreadBadge)}
oninput={onShowBadgeOnUnreadToggle} />
</div>
<div class="flex justify-between">
<p>Play sound for new direct messages</p>
<input
type="checkbox"
class="toggle toggle-primary"
checked={Boolean($playAlertSound)}
oninput={onDirectMessagesNotificationSoundToggle} />
</div> </div>
{#if $dmStatus} {#if $dmStatus}
{@const status = getTagValue("status", $dmStatus.tags) || "error"} {@const status = getTagValue("status", $dmStatus.tags) || "error"}

View File

@@ -425,6 +425,18 @@ export const dmAlert = derived(alerts, $alerts =>
}), }),
) )
export const showUnreadBadge = synced({
key: "showUnreadBadge",
defaultValue: true,
storage: preferencesStorageProvider,
})
export const playAlertSound = synced({
key: "playAlertSound",
defaultValue: true,
storage: preferencesStorageProvider,
})
// Alert Statuses // Alert Statuses
export type AlertStatus = { export type AlertStatus = {