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

130 lines
4.2 KiB
Svelte
Raw Normal View History

2024-10-03 21:32:55 +00:00
<script lang="ts">
2024-10-09 23:15:09 +00:00
import {ctx} from "@welshman/lib"
2024-10-17 22:48:35 +00:00
import {getListTags, createEvent, getPubkeyTagValues, MUTES} from "@welshman/util"
2024-10-17 22:46:26 +00:00
import {pubkey, signer, userMutes, tagPubkey, publishThunk} from "@welshman/app"
2025-02-04 03:28:29 +00:00
import {preventDefault} from "@lib/html"
2024-10-08 18:39:16 +00:00
import Field from "@lib/components/Field.svelte"
2024-10-17 22:21:22 +00:00
import FieldInline from "@lib/components/FieldInline.svelte"
2025-01-28 22:44:43 +00:00
import Icon from "@lib/components/Icon.svelte"
2024-10-08 18:39:16 +00:00
import Button from "@lib/components/Button.svelte"
import ProfileMultiSelect from "@app/components/ProfileMultiSelect.svelte"
import {pushToast} from "@app/toast"
2024-10-24 18:02:16 +00:00
import {SETTINGS, PLATFORM_NAME, userSettingValues} from "@app/state"
2024-10-17 23:03:50 +00:00
2024-10-03 21:32:55 +00:00
const reset = () => {
2024-10-08 18:39:16 +00:00
mutedPubkeys = getPubkeyTagValues(getListTags($userMutes))
2024-10-24 18:02:16 +00:00
settings = {...$userSettingValues}
2024-10-03 21:32:55 +00:00
}
2025-02-04 03:28:29 +00:00
const onsubmit = preventDefault(async () => {
2024-10-17 22:46:26 +00:00
publishThunk({
2024-10-17 22:48:35 +00:00
event: createEvent(SETTINGS, {
2024-10-17 22:46:26 +00:00
content: await $signer!.nip04.encrypt($pubkey!, JSON.stringify(settings)),
}),
2024-11-12 21:32:54 +00:00
relays: ctx.app.router.FromUser().getUrls(),
2024-10-17 22:46:26 +00:00
})
2024-10-08 22:30:18 +00:00
publishThunk({
event: createEvent(MUTES, {tags: mutedPubkeys.map(tagPubkey)}),
2024-11-12 21:32:54 +00:00
relays: ctx.app.router.FromUser().getUrls(),
2024-10-08 22:30:18 +00:00
})
2024-10-03 21:32:55 +00:00
pushToast({message: "Your settings have been saved!"})
2025-02-04 03:28:29 +00:00
})
2024-10-17 22:46:26 +00:00
2025-02-04 00:37:14 +00:00
let settings = $state({...$userSettingValues})
let mutedPubkeys = $state(getPubkeyTagValues(getListTags($userMutes)))
2024-10-03 21:32:55 +00:00
</script>
2025-02-04 03:28:29 +00:00
<form class="content column gap-4" {onsubmit}>
2024-10-17 23:03:50 +00:00
<div class="card2 bg-alt col-4 shadow-xl">
2024-10-31 17:37:20 +00:00
<p class="text-lg">Content Settings</p>
2024-10-17 22:21:22 +00:00
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Hide sensitive content?</p>
{/snippet}
{#snippet input()}
<input
type="checkbox"
class="toggle toggle-primary"
bind:checked={settings.hide_sensitive} />
{/snippet}
{#snippet info()}
<p>
If content is marked by the author as sensitive, {PLATFORM_NAME} will hide it by default.
</p>
{/snippet}
2024-10-17 22:21:22 +00:00
</FieldInline>
2024-10-24 18:02:16 +00:00
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Show media?</p>
{/snippet}
{#snippet input()}
<input type="checkbox" class="toggle toggle-primary" bind:checked={settings.show_media} />
{/snippet}
{#snippet info()}
<p>Use this to disable link previews and image rendering.</p>
{/snippet}
2024-10-24 18:02:16 +00:00
</FieldInline>
<Field>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Muted Accounts</p>
{/snippet}
{#snippet input()}
<div>
<ProfileMultiSelect bind:value={mutedPubkeys} />
</div>
{/snippet}
2024-10-24 18:02:16 +00:00
</Field>
2024-10-31 17:37:20 +00:00
<p class="text-lg">Editor Settings</p>
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Send Delay</p>
{/snippet}
{#snippet input()}
<input
class="range range-primary"
type="range"
min="0"
max="10000"
step="1000"
bind:value={settings.send_delay} />
{/snippet}
{#snippet info()}
<p>
Delay sending chat messages for {settings.send_delay / 1000}
{settings.send_delay === 1000 ? "second" : "seconds"}.
</p>
{/snippet}
2024-10-31 17:37:20 +00:00
</FieldInline>
2025-01-28 22:44:43 +00:00
<Field>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Media Server</p>
{/snippet}
{#snippet input()}
<div class="flex flex-col gap-2 sm:flex-row">
<select bind:value={settings.upload_type} class="select select-bordered">
<option value="nip96">NIP 96 (default)</option>
<option value="blossom">Blossom</option>
</select>
<label class="input input-bordered flex flex-grow items-center gap-2">
<Icon icon="link-round" />
{#if settings.upload_type === "nip96"}
<input class="grow" bind:value={settings.nip96_urls[0]} />
{:else}
<input class="grow" bind:value={settings.blossom_urls[0]} />
{/if}
</label>
</div>
{/snippet}
{#snippet info()}
<p>Choose a media server type and url for files you upload to flotilla.</p>
{/snippet}
2025-01-28 22:44:43 +00:00
</Field>
2024-10-08 18:39:16 +00:00
<div class="mt-4 flex flex-row items-center justify-between gap-4">
<Button class="btn btn-neutral" onclick={reset}>Discard Changes</Button>
2024-10-08 18:39:16 +00:00
<Button type="submit" class="btn btn-primary">Save Changes</Button>
2024-10-03 21:32:55 +00:00
</div>
</div>
</form>