feat: add tagline managing
This commit is contained in:
1 parent
01b4102c73
commit
45f5840498
2 files changed
+140
-2
No files matched your search
@@ -7,8 +7,8 @@
|
||||
<div class="flex flex-col gap-4 h-full">
|
||||
<MultiSelect
|
||||
headless
|
||||
options={['/admin/config', '/admin/applications']}
|
||||
optionNames={['Configuration', 'Applications']}
|
||||
options={['/admin/config', '/admin/applications', '/admin/taglines']}
|
||||
optionNames={['Configuration', 'Applications', 'Taglines']}
|
||||
selected={$page.url.pathname}
|
||||
on:select={(e) => {
|
||||
goto(e.detail)
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import EditableList from '$lib/components/ui/list/EditableList.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { Icon, Plus, QuestionMarkCircle, Trash } from 'svelte-hero-icons'
|
||||
|
||||
export let data
|
||||
|
||||
let taglines = [...(data.site?.taglines.map((t) => t.content) ?? [])]
|
||||
let newTagline = ''
|
||||
|
||||
let saving = false
|
||||
|
||||
async function save() {
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
saving = true
|
||||
|
||||
try {
|
||||
await getClient().editSite({
|
||||
auth: $profile.jwt,
|
||||
taglines: taglines,
|
||||
})
|
||||
toast({
|
||||
content: 'Successfully saved taglines.',
|
||||
type: 'success',
|
||||
})
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
saving = false
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if taglines.length > 0}
|
||||
<div class="flex flex-row justify-between items-center">
|
||||
<h1 class="font-bold text-2xl">Taglines</h1>
|
||||
<Button
|
||||
color="primary"
|
||||
on:click={save}
|
||||
loading={saving}
|
||||
disabled={saving}
|
||||
size="lg"
|
||||
class="h-max"
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
<EditableList
|
||||
let:action
|
||||
on:action={(e) => {
|
||||
taglines.splice(
|
||||
taglines.findIndex((i) => i == e.detail),
|
||||
1
|
||||
)
|
||||
|
||||
// hack for reactivity
|
||||
taglines = taglines
|
||||
}}
|
||||
>
|
||||
{#each taglines as tagline}
|
||||
<div class="flex py-3">
|
||||
<Markdown source={tagline} inline />
|
||||
|
||||
<div class="flex gap-2 ml-auto">
|
||||
<Button on:click={() => action(tagline)} size="square-md">
|
||||
<Icon src={Trash} mini size="16" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
<form
|
||||
class="flex flex-col mt-auto gap-2 w-full"
|
||||
on:submit|preventDefault={() => {
|
||||
if (newTagline == '' || !data.site) return
|
||||
|
||||
taglines = [...taglines, newTagline]
|
||||
|
||||
newTagline = ''
|
||||
}}
|
||||
>
|
||||
<MarkdownEditor
|
||||
bind:value={newTagline}
|
||||
placeholder="Add a tagline"
|
||||
images={false}
|
||||
/>
|
||||
|
||||
<Button size="lg" submit>
|
||||
<Icon src={Plus} size="16" mini slot="icon" />
|
||||
Add one
|
||||
</Button>
|
||||
</form>
|
||||
{:else}
|
||||
<div class="my-auto">
|
||||
<Placeholder>
|
||||
<Icon src={QuestionMarkCircle} solid size="32" slot="icon" />
|
||||
<span slot="title">No taglines</span>
|
||||
<div slot="action" class=" mt-4 w-full flex flex-col gap-2">
|
||||
<form
|
||||
class="flex flex-col gap-2 w-full"
|
||||
on:submit|preventDefault={() => {
|
||||
if (newTagline == '' || !data.site) return
|
||||
|
||||
taglines = [...taglines, newTagline]
|
||||
|
||||
newTagline = ''
|
||||
}}
|
||||
>
|
||||
<MarkdownEditor
|
||||
bind:value={newTagline}
|
||||
placeholder="Add a tagline"
|
||||
images={false}
|
||||
/>
|
||||
|
||||
<Button size="lg" submit>
|
||||
<Icon src={Plus} size="16" mini slot="icon" />
|
||||
Add one
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<Button on:click={save} color="primary" size="lg" class="w-full">
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</Placeholder>
|
||||
</div>
|
||||
{/if}
|
||||
Reference in new issue
Block a user