impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
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>
|
||||
Reference in new issue
Block a user