feat: add user notes
This commit is contained in:
9 files changed
+117
-2
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user