flotilla/src/routes/settings/privacy/+page.svelte

149 lines
4.7 KiB
Svelte
Raw Normal View History

2026-01-16 21:49:35 +00:00
<script lang="ts">
2026-09-07 21:39:01 +00:00
import {publish} from "@welshman/app"
2026-03-11 22:48:36 +00:00
import ShieldMinimalistic from "@assets/icons/shield-minimalistic.svg?dataurl"
2026-09-07 21:39:01 +00:00
import ForbiddenCircle from "@assets/icons/forbidden-circle.svg?dataurl"
2026-01-16 21:49:35 +00:00
import {preventDefault} from "@lib/html"
import FieldInline from "@lib/components/FieldInline.svelte"
2026-07-15 16:30:17 +00:00
import ToggleInput from "@lib/components/ToggleInput.svelte"
2026-03-11 22:48:36 +00:00
import Icon from "@lib/components/Icon.svelte"
import Card from "@lib/components/Card.svelte"
import PageContent from "@lib/components/PageContent.svelte"
2026-01-16 21:49:35 +00:00
import Button from "@lib/components/Button.svelte"
2026-08-13 19:57:42 +00:00
import Spinner from "@lib/components/Spinner.svelte"
2026-09-07 21:39:01 +00:00
import RelayList from "@app/components/RelayList.svelte"
import {blockedRelayLists, user} from "@app/core"
import {pushModal} from "@app/modal"
2026-06-08 21:14:40 +00:00
import {pushToast} from "@app/toast"
import {PLATFORM_NAME} from "@app/env"
2026-08-13 19:57:42 +00:00
import {sendLogs} from "@app/logger"
2026-08-22 20:12:11 +00:00
import {
RelayAuthMode,
userSettingsValues,
publishSettings,
createSettingsForm,
} from "@app/settings"
2026-01-16 21:49:35 +00:00
const reset = () => {
2026-08-22 20:12:11 +00:00
settings.set({...$userSettingsValues})
2026-01-16 21:49:35 +00:00
}
2026-08-13 19:57:42 +00:00
const send = async () => {
sendingLogs = true
2026-08-13 19:57:42 +00:00
try {
const thunk = await sendLogs()
const error = await thunk.waitForError()
if (error) {
pushToast({theme: "error", message: error})
} else {
pushToast({message: "Your logs have been sent. Thank you!"})
}
} finally {
sendingLogs = false
2026-08-13 19:57:42 +00:00
}
}
2026-07-15 16:30:17 +00:00
const onAuthModeChange = (checked: boolean) => {
2026-08-22 20:12:11 +00:00
$settings.relay_auth = checked ? RelayAuthMode.Aggressive : RelayAuthMode.Conservative
2026-01-16 21:49:35 +00:00
}
2026-09-07 21:39:01 +00:00
const showBlockedRelays = () =>
pushModal(RelayList, {
title: "Blocked Relays",
subtitle: "These relays won't be used unless explicitly requested.",
relays: blockedRelayUrls,
addRelay: (url: string) => $blockedRelayLists.addUrl(url).then(publish),
removeRelay: (url: string) => $blockedRelayLists.removeUrl(url).then(publish),
})
2026-01-16 21:49:35 +00:00
const onsubmit = preventDefault(async () => {
loading = true
try {
await publishSettings($settings)
2026-01-16 21:49:35 +00:00
pushToast({message: "Your settings have been saved!"})
} finally {
loading = false
}
2026-01-16 21:49:35 +00:00
})
2026-08-22 20:12:11 +00:00
const settings = createSettingsForm()
2026-09-07 21:39:01 +00:00
const blockedRelayUrls = $blockedRelayLists.urls($user.pubkey).$
2026-08-13 19:57:42 +00:00
let loading = $state(false)
let sendingLogs = $state(false)
2026-01-16 21:49:35 +00:00
</script>
<form {onsubmit}>
<PageContent>
<Card class="flex flex-col gap-4">
<strong class="flex items-center gap-3 text-lg">
<Icon icon={ShieldMinimalistic} />
Privacy Settings
</strong>
<FieldInline>
{#snippet label()}
<p>Authenticate with unknown relays?</p>
{/snippet}
{#snippet input()}
2026-07-15 16:30:17 +00:00
<ToggleInput
2026-08-22 20:12:11 +00:00
checked={$settings.relay_auth === RelayAuthMode.Aggressive}
2026-07-15 16:30:17 +00:00
onchange={onAuthModeChange} />
{/snippet}
{#snippet info()}
<p>Controls whether {PLATFORM_NAME} will identify you to relays not in your lists.</p>
{/snippet}
</FieldInline>
2026-09-07 21:39:01 +00:00
<FieldInline>
{#snippet label()}
<p>Blocked relays</p>
{/snippet}
{#snippet input()}
<Button class="button button-neutral" onclick={showBlockedRelays}>
<Icon icon={ForbiddenCircle} />
{$blockedRelayUrls.length} Blocked
</Button>
{/snippet}
{#snippet info()}
<p>These relays won't be used unless explicitly requested.</p>
{/snippet}
</FieldInline>
<FieldInline>
{#snippet label()}
2026-08-13 19:57:42 +00:00
<p>Report usage?</p>
{/snippet}
{#snippet input()}
2026-08-22 20:12:11 +00:00
<ToggleInput bind:checked={$settings.report_usage} />
{/snippet}
{#snippet info()}
2026-08-13 19:57:42 +00:00
<p>Allow {PLATFORM_NAME} to collect anonymous usage data.</p>
{/snippet}
</FieldInline>
<FieldInline>
{#snippet label()}
2026-08-13 19:57:42 +00:00
<p>Something went wrong?</p>
{/snippet}
{#snippet input()}
<Button class="button button-neutral" onclick={send} disabled={sendingLogs}>
<Spinner loading={sendingLogs}>Send Logs</Spinner>
2026-08-13 19:57:42 +00:00
</Button>
{/snippet}
{#snippet info()}
2026-08-13 19:57:42 +00:00
<p>
Send a record of recent app activity to the {PLATFORM_NAME} team as a direct message.
</p>
{/snippet}
</FieldInline>
</Card>
<Card class="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 class="button button-primary" type="submit" disabled={loading}>
<Spinner {loading}>Save Changes</Spinner>
</Button>
</Card>
</PageContent>
2026-01-16 21:49:35 +00:00
</form>