feat: add user settings to profile page
This commit is contained in:
1 parent
d193719475
commit
61a483e9ef
4 files changed
+104
-6
No files matched your search
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
export let checked: boolean
|
||||
export let checked: boolean | undefined = false
|
||||
const dispatcher = createEventDispatcher<{ change: boolean }>()
|
||||
</script>
|
||||
|
||||
<label class="flex flex-row items-center gap-2 cursor-pointer text-sm">
|
||||
<label class="flex flex-row gap-2 cursor-pointer text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked
|
||||
|
||||
@@ -1 +1,95 @@
|
||||
hi
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { SaveUserSettings } from 'lemmy-js-client'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let data
|
||||
|
||||
let formData: Omit<SaveUserSettings, 'auth'> | undefined = {
|
||||
...data.local_user_view?.local_user,
|
||||
...data.local_user_view?.person,
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!formData || !$profile?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const res = await getClient().saveUserSettings({
|
||||
auth: $profile.jwt,
|
||||
...formData,
|
||||
})
|
||||
toast({
|
||||
content: 'Saved your user settings.',
|
||||
type: 'success',
|
||||
})
|
||||
if (res.verify_email_sent) {
|
||||
toast({
|
||||
content: 'A verification email was sent.',
|
||||
type: 'info',
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
|
||||
let loading = false
|
||||
</script>
|
||||
|
||||
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
||||
<h1 class="font-bold text-2xl">User settings</h1>
|
||||
{#if data.local_user_view?.local_user && formData}
|
||||
<TextInput
|
||||
label="Display name"
|
||||
bind:value={formData.display_name}
|
||||
placeholder="Optional"
|
||||
/>
|
||||
<MarkdownEditor
|
||||
images={false}
|
||||
bind:value={formData.bio}
|
||||
label="Bio"
|
||||
previewButton
|
||||
/>
|
||||
<TextInput label="Email" bind:value={formData.email} />
|
||||
<TextInput
|
||||
label="Matrix User"
|
||||
bind:value={formData.matrix_user_id}
|
||||
placeholder="@user:example.com"
|
||||
/>
|
||||
<Checkbox bind:checked={formData.show_nsfw}>Show NSFW content</Checkbox>
|
||||
<Checkbox bind:checked={formData.show_scores}>Show Scores</Checkbox>
|
||||
<Checkbox bind:checked={formData.bot_account}>Bot Account</Checkbox>
|
||||
<Checkbox bind:checked={formData.show_bot_accounts}>
|
||||
Show Bot Accounts
|
||||
</Checkbox>
|
||||
<Checkbox bind:checked={formData.show_read_posts}>Show Read Posts</Checkbox>
|
||||
|
||||
<Button
|
||||
submit
|
||||
size="lg"
|
||||
color="primary"
|
||||
class="mt-auto"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
{:else}
|
||||
<Card cardColor="warning" class="p-5">
|
||||
The API didn't return your user settings.
|
||||
</Card>
|
||||
{/if}
|
||||
</form>
|
||||
@@ -0,0 +1,7 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load() {
|
||||
return (await getClient().getSite({ auth: get(profile)?.jwt })).my_user
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export async function load({ parent }) {
|
||||
return await parent()
|
||||
}
|
||||
Reference in new issue
Block a user