feat: add user notes

This commit is contained in:
Xylight committed 2025-11-15 19:34:20 -08:00
1 parent 1e09647e5d
commit edaa5e4772
9 files changed
+117 -2

No files matched your search

+1 -1
View File
@@ -76,7 +76,7 @@
{#if client() instanceof PiefedClient}
<div class="mb-3">
<MultiSelect
options={['normal', 'poll', 'event']}
options={['normal', 'poll']}
optionNames={[
$t('form.post.types.normal'),
$t('form.post.types.poll'),
+5
View File
@@ -148,6 +148,11 @@
{user.flair}
</Badge>
{/if}
{#if user.note}
<Badge color="gray-subtle" class="px-1.5! py-0.5! whitespace-nowrap">
{user.note}
</Badge>
{/if}
{@render extraBadges?.()}
{/if}
</a>
+58
View File
@@ -0,0 +1,58 @@
<script lang="ts">
import { client } from '$lib/api/client.svelte'
import { errorMessage } from '$lib/app/error'
import { t } from '$lib/app/i18n'
import { Button, TextInput, toast } from 'mono-svelte'
interface Props {
note?: string
person: number
onsubmit?: (note: string | null) => void
}
let { note: passedNote = '', person, onsubmit }: Props = $props()
let note = $state(passedNote)
// man wtf is this
let loading = $state<boolean | null>(false)
async function submit(note: string | null) {
try {
loading = note ? true : null
if (!client().setNote) throw new Error('unsupported')
await client().setNote!({ person_id: person, note: note })
onsubmit?.(note)
} catch (err) {
toast({
content: errorMessage(err as string),
type: 'error',
})
}
loading = false
}
</script>
<form
onsubmit={(e) => {
e.preventDefault()
submit(note)
}}
class="contents"
>
<TextInput bind:value={note} label={$t('nav.commands.content')} required />
<div class="flex flex-row gap-2 *:flex-1">
<Button loading={loading === true} submit color="primary" size="lg">
{$t('form.submit')}
</Button>
<Button
onclick={() => submit(null)}
loading={loading === null}
color="danger"
size="lg"
>
{$t('common.remove')}
</Button>
</div>
</form>