feat: add flairsettings
This commit is contained in:
10 files changed
+125
-11
No files matched your search
@@ -214,4 +214,18 @@ export abstract class BaseClient {
|
|||||||
abstract uploadImage(
|
abstract uploadImage(
|
||||||
form: types.UploadImage,
|
form: types.UploadImage,
|
||||||
): Promise<types.UploadImageResponse>
|
): Promise<types.UploadImageResponse>
|
||||||
|
|
||||||
|
abstract setFlair?(form: types.SetPersonFlair): Promise<types.PersonView>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type NullableFnArg<T, Fallback = never> = T extends (
|
||||||
|
...args: infer A
|
||||||
|
) => any
|
||||||
|
? A
|
||||||
|
: Fallback
|
||||||
|
|
||||||
|
export type NullableFnReturn<T, Fallback = never> = T extends (
|
||||||
|
...args: any[]
|
||||||
|
) => infer A
|
||||||
|
? A
|
||||||
|
: Fallback
|
||||||
@@ -5,7 +5,7 @@ import { error } from '@sveltejs/kit'
|
|||||||
import { type GetSiteResponse } from '$lib/client/types'
|
import { type GetSiteResponse } from '$lib/client/types'
|
||||||
import { LemmyClient } from './lemmy/lemmy'
|
import { LemmyClient } from './lemmy/lemmy'
|
||||||
import { PiefedClient } from './piefed/piefed'
|
import { PiefedClient } from './piefed/piefed'
|
||||||
import { DEFAULT_CLIENT_TYPE, type ClientType } from './base'
|
import { DEFAULT_CLIENT_TYPE, type ClientType, BaseClient } from './base'
|
||||||
|
|
||||||
class SiteData {
|
class SiteData {
|
||||||
#data = $state<GetSiteResponse>()
|
#data = $state<GetSiteResponse>()
|
||||||
@@ -64,7 +64,7 @@ export function client({
|
|||||||
) => Promise<Response>
|
) => Promise<Response>
|
||||||
auth?: string
|
auth?: string
|
||||||
clientType?: ClientType
|
clientType?: ClientType
|
||||||
} = {}) {
|
} = {}): BaseClient {
|
||||||
if (!instanceURL)
|
if (!instanceURL)
|
||||||
instanceURL = profile.current.instance || DEFAULT_INSTANCE_URL
|
instanceURL = profile.current.instance || DEFAULT_INSTANCE_URL
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import createClient from 'openapi-fetch'
|
import createClient from 'openapi-fetch'
|
||||||
import type { BaseClient, ClientType } from '../base'
|
import type {
|
||||||
|
BaseClient,
|
||||||
|
ClientType,
|
||||||
|
NullableFnArg,
|
||||||
|
NullableFnReturn,
|
||||||
|
} from '../base'
|
||||||
import {
|
import {
|
||||||
fromCreateComment,
|
fromCreateComment,
|
||||||
fromCreatePost,
|
fromCreatePost,
|
||||||
@@ -26,6 +31,7 @@ import {
|
|||||||
toSortType,
|
toSortType,
|
||||||
} from './rewrite'
|
} from './rewrite'
|
||||||
import type { paths } from './schema'
|
import type { paths } from './schema'
|
||||||
|
import type { SetPersonFlair, PersonView } from '../types'
|
||||||
|
|
||||||
export class PiefedClient implements BaseClient {
|
export class PiefedClient implements BaseClient {
|
||||||
type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' }
|
type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' }
|
||||||
@@ -893,4 +899,14 @@ export class PiefedClient implements BaseClient {
|
|||||||
msg: 'yeah it worked i think',
|
msg: 'yeah it worked i think',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setFlair(
|
||||||
|
params: NullableFnArg<BaseClient['setFlair']>[0],
|
||||||
|
): NullableFnReturn<BaseClient['setFlair']> {
|
||||||
|
const response = (
|
||||||
|
await this.#client.POST('/user/set_flair', { body: params })
|
||||||
|
).data!
|
||||||
|
|
||||||
|
return toPersonView(response.person_view)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1985,3 +1985,8 @@ export interface DeleteImage {
|
|||||||
token: string
|
token: string
|
||||||
filename: string
|
filename: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SetPersonFlair {
|
||||||
|
community_id: number
|
||||||
|
flair_text: string
|
||||||
|
}
|
||||||
@@ -67,28 +67,31 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
|
import { client, getClient } from '$lib/client/lemmy.svelte'
|
||||||
|
import type { CommunityModeratorView, CommunityView } from '$lib/client/types'
|
||||||
import {
|
import {
|
||||||
amMod,
|
amMod,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||||
import Entity from '$lib/components/ui/Entity.svelte'
|
import Entity from '$lib/components/ui/Entity.svelte'
|
||||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||||
|
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { client, getClient } from '$lib/client/lemmy.svelte'
|
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
import { userLink } from '$lib/lemmy/generic'
|
import { userLink } from '$lib/lemmy/generic'
|
||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import { settings } from '$lib/settings.svelte'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { fullCommunityName } from '$lib/util.svelte.js'
|
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||||
import type { CommunityModeratorView, CommunityView } from '$lib/client/types'
|
|
||||||
import {
|
import {
|
||||||
action,
|
action,
|
||||||
Button,
|
Button,
|
||||||
Menu,
|
Menu,
|
||||||
MenuButton,
|
MenuButton,
|
||||||
|
Modal,
|
||||||
modal,
|
modal,
|
||||||
removeToast,
|
removeToast,
|
||||||
Spinner,
|
Spinner,
|
||||||
@@ -105,10 +108,10 @@
|
|||||||
NoSymbol,
|
NoSymbol,
|
||||||
Plus,
|
Plus,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
|
Tag,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import ItemList from '../generic/ItemList.svelte'
|
import ItemList from '../generic/ItemList.svelte'
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import CommunityFlair from './CommunityFlair.svelte'
|
||||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
|
||||||
|
|
||||||
let loading = $state({
|
let loading = $state({
|
||||||
blocking: false,
|
blocking: false,
|
||||||
@@ -135,6 +138,10 @@
|
|||||||
|
|
||||||
loading.subscribing = false
|
loading.subscribing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let setFlair = $state(false)
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
community_view: CommunityView | Promise<CommunityView>
|
community_view: CommunityView | Promise<CommunityView>
|
||||||
moderators?: CommunityModeratorView[]
|
moderators?: CommunityModeratorView[]
|
||||||
@@ -148,6 +155,7 @@
|
|||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
{#await community_view}
|
{#await community_view}
|
||||||
<div
|
<div
|
||||||
class="w-full h-full grid place-items-center"
|
class="w-full h-full grid place-items-center"
|
||||||
@@ -157,6 +165,9 @@
|
|||||||
<Spinner width={24} />
|
<Spinner width={24} />
|
||||||
</div>
|
</div>
|
||||||
{:then community_view}
|
{:then community_view}
|
||||||
|
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||||
|
<CommunityFlair community={community_view.community.id} onsubmit={() => setFlair = !setFlair} />
|
||||||
|
</Modal>
|
||||||
<aside
|
<aside
|
||||||
class={[
|
class={[
|
||||||
'min-w-full pt-0 text-slate-600 dark:text-zinc-400 flex flex-col gap-1',
|
'min-w-full pt-0 text-slate-600 dark:text-zinc-400 flex flex-col gap-1',
|
||||||
@@ -210,6 +221,14 @@
|
|||||||
? $t('cards.community.subscribed')
|
? $t('cards.community.subscribed')
|
||||||
: $t('cards.community.subscribe')}
|
: $t('cards.community.subscribe')}
|
||||||
</Button>
|
</Button>
|
||||||
|
{#if client().setFlair}
|
||||||
|
<SidebarButton
|
||||||
|
onclick={() => setFlair = !setFlair}
|
||||||
|
rounding="xl"
|
||||||
|
icon={Tag}
|
||||||
|
label={$t('cards.community.flair')}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
||||||
<SidebarButton
|
<SidebarButton
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { client } from '$lib/client/lemmy.svelte'
|
||||||
|
import { t } from '$lib/i18n/translations'
|
||||||
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
import { Button, TextInput, toast } from 'mono-svelte'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
flair?: string
|
||||||
|
community: number
|
||||||
|
onsubmit?: (flair: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
let { flair: passedFlair = '', community, onsubmit }: Props = $props()
|
||||||
|
let flair = $state(passedFlair)
|
||||||
|
let loading = $state(false)
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
try {
|
||||||
|
loading = true
|
||||||
|
if (!client().setFlair) throw new Error('unsupported')
|
||||||
|
|
||||||
|
await client().setFlair!({ community_id: community, flair_text: flair })
|
||||||
|
|
||||||
|
onsubmit?.(flair)
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: errorMessage(err as string),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form
|
||||||
|
onsubmit={e => {
|
||||||
|
e.preventDefault()
|
||||||
|
submit()
|
||||||
|
}}
|
||||||
|
class="contents"
|
||||||
|
>
|
||||||
|
<TextInput bind:value={flair} label={$t('nav.commands.content')} required />
|
||||||
|
<Button {loading} submit color="primary" size="lg">
|
||||||
|
{$t('form.submit')}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
CommunityModeratorView,
|
CommunityModeratorView,
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
} from '$lib/client/types'
|
} from '$lib/client/types'
|
||||||
import { action, Button, Menu, MenuButton, modal, toast } from 'mono-svelte'
|
import { action, Button, Menu, MenuButton, Modal, modal, toast } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
BuildingOffice2,
|
BuildingOffice2,
|
||||||
Check,
|
Check,
|
||||||
@@ -26,11 +26,13 @@
|
|||||||
NoSymbol,
|
NoSymbol,
|
||||||
Plus,
|
Plus,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
|
Tag,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
||||||
import ItemList from '../generic/ItemList.svelte'
|
import ItemList from '../generic/ItemList.svelte'
|
||||||
import { amMod, isAdmin } from '../moderation/moderation'
|
import { amMod, isAdmin } from '../moderation/moderation'
|
||||||
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
||||||
|
import CommunityFlair from './CommunityFlair.svelte'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
community: Community
|
community: Community
|
||||||
@@ -55,8 +57,15 @@
|
|||||||
compact,
|
compact,
|
||||||
...rest
|
...rest
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
|
let setFlair = $state(false)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||||
|
<CommunityFlair community={community.id} onsubmit={() => setFlair = !setFlair} />
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<EntityHeader
|
<EntityHeader
|
||||||
{...rest}
|
{...rest}
|
||||||
{compact}
|
{compact}
|
||||||
@@ -157,6 +166,10 @@
|
|||||||
</Button>
|
</Button>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Subscribe>
|
</Subscribe>
|
||||||
|
|
||||||
|
<Button size="custom" class="h-9 aspect-square" rounding="pill" onclick={() => setFlair = !setFlair} aria-label={$t('cards.community.flair')}>
|
||||||
|
<Icon src={Tag} size="16" micro />
|
||||||
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if profile.current?.user && profile.current.user.moderates
|
{#if profile.current?.user && profile.current.user.moderates
|
||||||
|
|||||||
@@ -142,7 +142,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if user.flair}
|
{#if user.flair}
|
||||||
<Badge>{user.flair}</Badge>
|
<Badge color="blue-subtle" class="px-1.5! py-0.5!">{user.flair}</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{@render extraBadges?.()}
|
{@render extraBadges?.()}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -498,7 +498,8 @@
|
|||||||
"block": "Block",
|
"block": "Block",
|
||||||
"unblock": "Unblock",
|
"unblock": "Unblock",
|
||||||
"blockInstance": "Block instance",
|
"blockInstance": "Block instance",
|
||||||
"activeDay": "Active Today"
|
"activeDay": "Active Today",
|
||||||
|
"flair": "Set my flair"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Snippet } from 'svelte'
|
import { type Snippet } from 'svelte'
|
||||||
import type { IconSource } from 'svelte-hero-icons'
|
import type { IconSource } from 'svelte-hero-icons'
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user