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
View File
@@ -236,6 +236,7 @@ export abstract class BaseClient {
abstract assignFlair?(form: types.AssignFlair): Promise<types.PostView>
abstract listMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
abstract voteOnPoll?(form: types.PollVote): Promise<types.PostView>
abstract setNote?(form: types.SetNote): Promise<types.PersonView>
}
export type NullableFnArg<T, Fallback = never> = T extends (
+10
View File
@@ -1030,4 +1030,14 @@ export class PiefedClient implements BaseClient {
return toPostView(response)
}
async setNote(
params: NullableFnArg<BaseClient['setNote']>[0],
): NullableFnReturn<BaseClient['setNote']> {
const response = (
await this.#client.POST('/api/alpha/user/note', { body: params })
).data!
return toPersonView(response.person_view)
}
}
+1 -1
View File
@@ -5582,7 +5582,7 @@ export interface components {
note: string
}
UserSetNoteResponse: {
person_view?: components['schemas']['PersonView']
person_view: components['schemas']['PersonView']
}
ListCommentsResponse: {
comments: components['schemas']['CommentView'][]
+11
View File
@@ -1883,6 +1883,12 @@ export interface Person {
ban_expires?: string
instance_id: InstanceId
flair?: string
extra_fields?: {
id: number
label: string
text: string
}[]
note?: string
}
export interface PersonAggregates {
@@ -2459,3 +2465,8 @@ export interface PollVote {
post_id: number
choice_id: number
}
export interface SetNote {
person_id: number
note: string | null
}
+3
View File
@@ -502,6 +502,9 @@
"manage": "Manage"
},
"languageWarning": "Content in this community is in languages you do not have selected. Some or all posts may be missing."
},
"user": {
"note": "Set note"
}
},
"cards": {
+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>
+27
View File
@@ -5,6 +5,7 @@
import { t } from '$lib/app/i18n'
import { ban } from '$lib/feature/moderation/moderation'
import { blockUser, isBlocked } from '$lib/feature/user'
import UserNote from '$lib/feature/user/UserNote.svelte'
import {
Button,
Menu,
@@ -23,11 +24,13 @@
NoSymbol,
ShieldCheck,
ShieldExclamation,
Tag,
} from 'svelte-hero-icons/dist'
let { person }: { person: PersonView } = $props()
let purgingUser = $state(false)
let setNote = $state(false)
async function purgeUser() {
purgingUser = false
@@ -67,6 +70,27 @@
</Modal>
{/if}
{#if setNote}
<Modal bind:open={setNote}>
{#snippet customTitle()}
{$t('routes.user.note')}
{/snippet}
<UserNote
person={person.person.id}
note={person.person.note}
onsubmit={(e) => {
// lol
person.person.note = e ?? undefined
setNote = !setNote
toast({
content: $t('message.success'),
type: 'success',
})
}}
/>
</Modal>
{/if}
{#if profile.current?.user && profile.current.jwt && person.person.id != profile.current.user.local_user_view.person.id}
<div class="flex items-center gap-2 w-full flex-wrap">
<Button
@@ -133,6 +157,9 @@
aria-label={$t('post.actions.more.label')}
/>
{/snippet}
<MenuButton onclick={() => (setNote = !setNote)} icon={Tag}>
{$t('routes.user.note')}
</MenuButton>
<MenuButton
color="danger-subtle"
onclick={() =>