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 assignFlair?(form: types.AssignFlair): Promise<types.PostView>
|
||||||
abstract listMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
|
abstract listMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
|
||||||
abstract voteOnPoll?(form: types.PollVote): Promise<types.PostView>
|
abstract voteOnPoll?(form: types.PollVote): Promise<types.PostView>
|
||||||
|
abstract setNote?(form: types.SetNote): Promise<types.PersonView>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NullableFnArg<T, Fallback = never> = T extends (
|
export type NullableFnArg<T, Fallback = never> = T extends (
|
||||||
|
|||||||
@@ -1030,4 +1030,14 @@ export class PiefedClient implements BaseClient {
|
|||||||
|
|
||||||
return toPostView(response)
|
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
|
note: string
|
||||||
}
|
}
|
||||||
UserSetNoteResponse: {
|
UserSetNoteResponse: {
|
||||||
person_view?: components['schemas']['PersonView']
|
person_view: components['schemas']['PersonView']
|
||||||
}
|
}
|
||||||
ListCommentsResponse: {
|
ListCommentsResponse: {
|
||||||
comments: components['schemas']['CommentView'][]
|
comments: components['schemas']['CommentView'][]
|
||||||
|
|||||||
@@ -1883,6 +1883,12 @@ export interface Person {
|
|||||||
ban_expires?: string
|
ban_expires?: string
|
||||||
instance_id: InstanceId
|
instance_id: InstanceId
|
||||||
flair?: string
|
flair?: string
|
||||||
|
extra_fields?: {
|
||||||
|
id: number
|
||||||
|
label: string
|
||||||
|
text: string
|
||||||
|
}[]
|
||||||
|
note?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PersonAggregates {
|
export interface PersonAggregates {
|
||||||
@@ -2459,3 +2465,8 @@ export interface PollVote {
|
|||||||
post_id: number
|
post_id: number
|
||||||
choice_id: number
|
choice_id: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SetNote {
|
||||||
|
person_id: number
|
||||||
|
note: string | null
|
||||||
|
}
|
||||||
@@ -502,6 +502,9 @@
|
|||||||
"manage": "Manage"
|
"manage": "Manage"
|
||||||
},
|
},
|
||||||
"languageWarning": "Content in this community is in languages you do not have selected. Some or all posts may be missing."
|
"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": {
|
"cards": {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
{#if client() instanceof PiefedClient}
|
{#if client() instanceof PiefedClient}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
options={['normal', 'poll', 'event']}
|
options={['normal', 'poll']}
|
||||||
optionNames={[
|
optionNames={[
|
||||||
$t('form.post.types.normal'),
|
$t('form.post.types.normal'),
|
||||||
$t('form.post.types.poll'),
|
$t('form.post.types.poll'),
|
||||||
|
|||||||
@@ -148,6 +148,11 @@
|
|||||||
{user.flair}
|
{user.flair}
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if user.note}
|
||||||
|
<Badge color="gray-subtle" class="px-1.5! py-0.5! whitespace-nowrap">
|
||||||
|
{user.note}
|
||||||
|
</Badge>
|
||||||
|
{/if}
|
||||||
{@render extraBadges?.()}
|
{@render extraBadges?.()}
|
||||||
{/if}
|
{/if}
|
||||||
</a>
|
</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>
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
import { t } from '$lib/app/i18n'
|
import { t } from '$lib/app/i18n'
|
||||||
import { ban } from '$lib/feature/moderation/moderation'
|
import { ban } from '$lib/feature/moderation/moderation'
|
||||||
import { blockUser, isBlocked } from '$lib/feature/user'
|
import { blockUser, isBlocked } from '$lib/feature/user'
|
||||||
|
import UserNote from '$lib/feature/user/UserNote.svelte'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Menu,
|
Menu,
|
||||||
@@ -23,11 +24,13 @@
|
|||||||
NoSymbol,
|
NoSymbol,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
ShieldExclamation,
|
ShieldExclamation,
|
||||||
|
Tag,
|
||||||
} from 'svelte-hero-icons/dist'
|
} from 'svelte-hero-icons/dist'
|
||||||
|
|
||||||
let { person }: { person: PersonView } = $props()
|
let { person }: { person: PersonView } = $props()
|
||||||
|
|
||||||
let purgingUser = $state(false)
|
let purgingUser = $state(false)
|
||||||
|
let setNote = $state(false)
|
||||||
|
|
||||||
async function purgeUser() {
|
async function purgeUser() {
|
||||||
purgingUser = false
|
purgingUser = false
|
||||||
@@ -67,6 +70,27 @@
|
|||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/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}
|
{#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">
|
<div class="flex items-center gap-2 w-full flex-wrap">
|
||||||
<Button
|
<Button
|
||||||
@@ -133,6 +157,9 @@
|
|||||||
aria-label={$t('post.actions.more.label')}
|
aria-label={$t('post.actions.more.label')}
|
||||||
/>
|
/>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
<MenuButton onclick={() => (setNote = !setNote)} icon={Tag}>
|
||||||
|
{$t('routes.user.note')}
|
||||||
|
</MenuButton>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
onclick={() =>
|
onclick={() =>
|
||||||
|
|||||||
Reference in new issue
Block a user