feat: add user notes
This commit is contained in:
9 files changed
+117
-2
No files matched your search
@@ -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 (
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -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'][]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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": {
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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