feat: add flairsettings

This commit is contained in:
James Xylight committed 2025-09-05 16:14:11 -07:00
1 parent 43654ca2d8
commit ab00f53cac
10 files changed
+125 -11

No files matched your search

@@ -67,28 +67,31 @@
<script lang="ts">
import { profile } from '$lib/auth.svelte.js'
import { client, getClient } from '$lib/client/lemmy.svelte'
import type { CommunityModeratorView, CommunityView } from '$lib/client/types'
import {
amMod,
isAdmin,
} from '$lib/components/lemmy/moderation/moderation.js'
import Markdown from '$lib/components/markdown/Markdown.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 Expandable from '$lib/components/ui/Expandable.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 { client, getClient } from '$lib/client/lemmy.svelte'
import { errorMessage } from '$lib/lemmy/error'
import { userLink } from '$lib/lemmy/generic'
import { addSubscription } from '$lib/lemmy/user.js'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName } from '$lib/util.svelte.js'
import type { CommunityModeratorView, CommunityView } from '$lib/client/types'
import {
action,
Button,
Menu,
MenuButton,
Modal,
modal,
removeToast,
Spinner,
@@ -105,10 +108,10 @@
NoSymbol,
Plus,
ShieldCheck,
Tag,
} from 'svelte-hero-icons'
import ItemList from '../generic/ItemList.svelte'
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import CommunityFlair from './CommunityFlair.svelte'
let loading = $state({
blocking: false,
@@ -135,6 +138,10 @@
loading.subscribing = false
}
let setFlair = $state(false)
interface Props {
community_view: CommunityView | Promise<CommunityView>
moderators?: CommunityModeratorView[]
@@ -148,6 +155,7 @@
}: Props = $props()
</script>
{#await community_view}
<div
class="w-full h-full grid place-items-center"
@@ -157,6 +165,9 @@
<Spinner width={24} />
</div>
{:then community_view}
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
<CommunityFlair community={community_view.community.id} onsubmit={() => setFlair = !setFlair} />
</Modal>
<aside
class={[
'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.subscribe')}
</Button>
{#if client().setFlair}
<SidebarButton
onclick={() => setFlair = !setFlair}
rounding="xl"
icon={Tag}
label={$t('cards.community.flair')}
/>
{/if}
{/if}
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
<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,
SubscribedType,
} 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 {
BuildingOffice2,
Check,
@@ -26,11 +26,13 @@
NoSymbol,
Plus,
ShieldCheck,
Tag,
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import ItemList from '../generic/ItemList.svelte'
import { amMod, isAdmin } from '../moderation/moderation'
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
import CommunityFlair from './CommunityFlair.svelte'
interface Props {
community: Community
@@ -55,8 +57,15 @@
compact,
...rest
}: Props = $props()
let setFlair = $state(false)
</script>
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
<CommunityFlair community={community.id} onsubmit={() => setFlair = !setFlair} />
</Modal>
<EntityHeader
{...rest}
{compact}
@@ -157,6 +166,10 @@
</Button>
{/snippet}
</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 profile.current?.user && profile.current.user.moderates
@@ -142,7 +142,7 @@
{/if}
{/if}
{#if user.flair}
<Badge>{user.flair}</Badge>
<Badge color="blue-subtle" class="px-1.5! py-0.5!">{user.flair}</Badge>
{/if}
{@render extraBadges?.()}
{/if}