misc: improve community management page
This commit is contained in:
1 parent
6291e7e3d3
commit
0ea98f41dc
5 files changed
+190
-44
No files matched your search
@@ -0,0 +1,56 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||||
|
import { Label, TextInput } from 'mono-svelte'
|
||||||
|
|
||||||
|
export let accept = 'image/*'
|
||||||
|
export let files: FileList | undefined | null = null
|
||||||
|
export let label: string | undefined = undefined
|
||||||
|
export let url: string | undefined = undefined
|
||||||
|
|
||||||
|
let dragover = false
|
||||||
|
|
||||||
|
$: previewURL = files ? URL.createObjectURL(files[0]) : undefined
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<Label text={label} class="mb-1">
|
||||||
|
<slot name="label" />
|
||||||
|
</Label>
|
||||||
|
<label
|
||||||
|
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
||||||
|
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
||||||
|
cursor-pointer min-h-36 transition-colors {dragover
|
||||||
|
? 'border-sky-500 text-sky-500'
|
||||||
|
: ''}
|
||||||
|
{url != undefined ? 'rounded-b-none' : ''}
|
||||||
|
"
|
||||||
|
on:drop|preventDefault={(event) => (files = event.dataTransfer?.files)}
|
||||||
|
on:dragover|preventDefault={(event) => {
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.dropEffect = 'copy'
|
||||||
|
dragover = true
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
on:dragleave|preventDefault={() => (dragover = false)}
|
||||||
|
>
|
||||||
|
{#if files}
|
||||||
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
|
<img
|
||||||
|
src={previewURL}
|
||||||
|
on:load={() => {
|
||||||
|
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||||
|
}}
|
||||||
|
class="w-full max-w-sm h-full rounded-lg"
|
||||||
|
/>
|
||||||
|
{:else if url}
|
||||||
|
<img src={url} />
|
||||||
|
{:else}
|
||||||
|
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||||
|
<p class="text-sm opacity-50">Attach a file</p>
|
||||||
|
{/if}
|
||||||
|
<input type="file" bind:files {accept} class="hidden" />
|
||||||
|
</label>
|
||||||
|
{#if url != undefined}
|
||||||
|
<TextInput class="rounded-t-none border-t-0 rounded-xl" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -2,13 +2,18 @@
|
|||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { ImageInput, toast } from 'mono-svelte'
|
import { ImageInput, Switch, toast } from 'mono-svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.js'
|
||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
||||||
import { uploadImage } from '$lib/util.js'
|
import { uploadImage } from '$lib/util.js'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
|
||||||
|
import Label from 'mono-svelte/forms/Label.svelte'
|
||||||
|
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||||
|
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
|
||||||
|
import Select from 'mono-svelte/forms/Select.svelte'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The community ID to edit.
|
* The community ID to edit.
|
||||||
@@ -18,21 +23,21 @@
|
|||||||
export let formData: {
|
export let formData: {
|
||||||
name: string
|
name: string
|
||||||
displayName: string
|
displayName: string
|
||||||
icon: FileList | null
|
icon?: string
|
||||||
banner: FileList | null
|
banner?: string
|
||||||
sidebar: string
|
sidebar?: string
|
||||||
nsfw: boolean
|
nsfw: boolean
|
||||||
postsLockedToModerators: boolean
|
postsLockedToModerators: boolean
|
||||||
submitting: boolean
|
submitting: boolean
|
||||||
|
visibility: 'Public' | 'LocalOnly'
|
||||||
} = {
|
} = {
|
||||||
name: '',
|
name: '',
|
||||||
displayName: '',
|
displayName: '',
|
||||||
icon: null,
|
|
||||||
banner: null,
|
|
||||||
sidebar: '',
|
sidebar: '',
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
postsLockedToModerators: false,
|
postsLockedToModerators: false,
|
||||||
submitting: false,
|
submitting: false,
|
||||||
|
visibility: 'Public',
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
@@ -42,22 +47,16 @@
|
|||||||
formData.submitting = true
|
formData.submitting = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let icon = formData.icon
|
|
||||||
? await uploadImage(formData.icon[0], $profile.instance, $profile.jwt)
|
|
||||||
: undefined
|
|
||||||
let banner = formData.banner
|
|
||||||
? await uploadImage(formData.banner[0], $profile.instance, $profile.jwt)
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
const res = edit
|
const res = edit
|
||||||
? await getClient().editCommunity({
|
? await getClient().editCommunity({
|
||||||
title: formData.displayName,
|
title: formData.displayName,
|
||||||
description: formData.sidebar,
|
description: formData.sidebar,
|
||||||
nsfw: formData.nsfw,
|
nsfw: formData.nsfw,
|
||||||
posting_restricted_to_mods: formData.postsLockedToModerators,
|
posting_restricted_to_mods: formData.postsLockedToModerators,
|
||||||
icon: icon,
|
icon: formData.icon,
|
||||||
banner: banner,
|
banner: formData.banner,
|
||||||
community_id: edit,
|
community_id: edit,
|
||||||
|
visibility: formData.visibility,
|
||||||
})
|
})
|
||||||
: await getClient().createCommunity({
|
: await getClient().createCommunity({
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
@@ -65,8 +64,9 @@
|
|||||||
description: formData.sidebar,
|
description: formData.sidebar,
|
||||||
nsfw: formData.nsfw,
|
nsfw: formData.nsfw,
|
||||||
posting_restricted_to_mods: formData.postsLockedToModerators,
|
posting_restricted_to_mods: formData.postsLockedToModerators,
|
||||||
icon: icon,
|
icon: formData.icon,
|
||||||
banner: banner,
|
banner: formData.banner,
|
||||||
|
visibility: formData.visibility,
|
||||||
})
|
})
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@@ -114,6 +114,11 @@
|
|||||||
|
|
||||||
formData.submitting = false
|
formData.submitting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let uploading = {
|
||||||
|
banner: false,
|
||||||
|
icon: false,
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
@@ -137,18 +142,78 @@
|
|||||||
label={$t('form.profile.displayName')}
|
label={$t('form.profile.displayName')}
|
||||||
bind:value={formData.displayName}
|
bind:value={formData.displayName}
|
||||||
/>
|
/>
|
||||||
<ImageInput label={$t('form.profile.avatar')} bind:files={formData.icon} />
|
<div class="flex flex-row gap-4 flex-wrap *:flex-1">
|
||||||
<ImageInput label={$t('form.profile.banner')} bind:files={formData.banner} />
|
<div class="flex flex-col gap-1">
|
||||||
|
<Label>{$t('routes.admin.config.icon')}</Label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
on:click={() => (uploading.icon = !uploading.icon)}
|
||||||
|
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||||
|
>
|
||||||
|
{#if formData.icon}
|
||||||
|
<img src={formData.icon} alt="" class="rounded-md mx-auto h-full" />
|
||||||
|
{:else}
|
||||||
|
<Icon
|
||||||
|
src={DocumentPlus}
|
||||||
|
size="48"
|
||||||
|
class="text-slate-500 dark:text-zinc-500 mx-auto my-auto"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{#if uploading.icon}
|
||||||
|
<ImageUploadModal
|
||||||
|
bind:open={uploading.icon}
|
||||||
|
multiple={false}
|
||||||
|
on:upload={(uploaded) => {
|
||||||
|
uploading.icon = false
|
||||||
|
formData.icon = uploaded.detail[0]
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<Label>{$t('routes.admin.config.banner')}</Label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
on:click={() => (uploading.banner = !uploading.banner)}
|
||||||
|
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||||
|
>
|
||||||
|
{#if formData.banner}
|
||||||
|
<img src={formData.banner} alt="" class="rounded-md mx-auto h-full" />
|
||||||
|
{:else}
|
||||||
|
<Icon
|
||||||
|
src={DocumentPlus}
|
||||||
|
size="48"
|
||||||
|
class="text-slate-500 dark:text-zinc-500 mx-auto my-auto"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{#if uploading.banner}
|
||||||
|
<ImageUploadModal
|
||||||
|
bind:open={uploading.banner}
|
||||||
|
multiple={false}
|
||||||
|
on:upload={(uploaded) => {
|
||||||
|
uploading.banner = false
|
||||||
|
formData.banner = uploaded.detail[0]
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
previewButton
|
previewButton
|
||||||
label={$t('routes.admin.config.sidebar')}
|
label={$t('routes.admin.config.sidebar')}
|
||||||
bind:value={formData.sidebar}
|
bind:value={formData.sidebar}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Checkbox bind:checked={formData.nsfw}>{$t('post.badges.nsfw')}</Checkbox>
|
<Switch bind:checked={formData.nsfw}>{$t('post.badges.nsfw')}</Switch>
|
||||||
<Checkbox bind:checked={formData.postsLockedToModerators}>
|
<Switch bind:checked={formData.postsLockedToModerators}>
|
||||||
Only moderators can post
|
Only moderators can post
|
||||||
</Checkbox>
|
</Switch>
|
||||||
|
<Select label="Visibility" class="w-max" bind:value={formData.visibility}>
|
||||||
|
<option value="Public">Public</option>
|
||||||
|
<option value="LocalOnly">Local Only</option>
|
||||||
|
</Select>
|
||||||
<Button
|
<Button
|
||||||
submit
|
submit
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|||||||
@@ -413,7 +413,8 @@
|
|||||||
"community": {
|
"community": {
|
||||||
"settings": {
|
"settings": {
|
||||||
"team": "Team",
|
"team": "Team",
|
||||||
"settings": "Settings"
|
"settings": "Settings",
|
||||||
|
"manage": "Manage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CommunityForm from '$lib/components/lemmy/community/CommunityForm.svelte'
|
import CommunityForm from '$lib/components/lemmy/community/CommunityForm.svelte'
|
||||||
import CommunityTitle from '$lib/components/lemmy/community/CommunityTitle.svelte'
|
import CommunityTitle from '$lib/components/lemmy/community/CommunityTitle.svelte'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
<CommunityTitle community={data.community.community_view.community} />
|
<Header pageHeader>
|
||||||
<h1 class="font-bold text-2xl">Settings</h1>
|
<span>Settings</span>
|
||||||
|
<CommunityTitle
|
||||||
|
slot="extended"
|
||||||
|
community={data.community.community_view.community}
|
||||||
|
/>
|
||||||
|
</Header>
|
||||||
<CommunityForm
|
<CommunityForm
|
||||||
edit={data.community.community_view.community.id}
|
edit={data.community.community_view.community.id}
|
||||||
formData={{
|
formData={{
|
||||||
@@ -17,8 +23,9 @@
|
|||||||
postsLockedToModerators:
|
postsLockedToModerators:
|
||||||
data.community.community_view.community.posting_restricted_to_mods,
|
data.community.community_view.community.posting_restricted_to_mods,
|
||||||
sidebar: data.community.community_view.community.description ?? '',
|
sidebar: data.community.community_view.community.description ?? '',
|
||||||
icon: null,
|
icon: data.community.community_view.community.icon,
|
||||||
banner: null,
|
banner: data.community.community_view.community.banner,
|
||||||
|
visibility: data.community.community_view.community.visibility,
|
||||||
submitting: false,
|
submitting: false,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import type { PageData } from './$types.js'
|
import type { PageData } from './$types.js'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.js'
|
||||||
import { flip } from 'svelte/animate'
|
import { flip } from 'svelte/animate'
|
||||||
import { Button, TextInput } from 'mono-svelte'
|
import { Button, TextInput } from 'mono-svelte'
|
||||||
import { t } from '$lib/translations.js'
|
import { t } from '$lib/translations.js'
|
||||||
@@ -25,30 +25,46 @@
|
|||||||
formData.addingModerator = true
|
formData.addingModerator = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getClient().resolveObject({
|
if (Number(formData.newModerator)) {
|
||||||
q: formData.newModerator,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (res.person) {
|
|
||||||
const addModRes = await getClient().addModToCommunity({
|
const addModRes = await getClient().addModToCommunity({
|
||||||
added: true,
|
added: true,
|
||||||
person_id: res.person.person.id,
|
person_id: Number(formData.newModerator),
|
||||||
community_id: data.community.community_view.community.id,
|
community_id: data.community.community_view.community.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
data.community.moderators = addModRes.moderators
|
data.community.moderators = addModRes.moderators
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: $t('toast.addMod'),
|
content: $t('toast.addMod'),
|
||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
formData.newModerator = ''
|
formData.newModerator = ''
|
||||||
} else {
|
} else if (formData.newModerator) {
|
||||||
toast({
|
const res = await getClient().resolveObject({
|
||||||
content: $t('toast.failFindUser'),
|
q: formData.newModerator,
|
||||||
type: 'warning',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (res.person) {
|
||||||
|
const addModRes = await getClient().addModToCommunity({
|
||||||
|
added: true,
|
||||||
|
person_id: res.person.person.id,
|
||||||
|
community_id: data.community.community_view.community.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
data.community.moderators = addModRes.moderators
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: $t('toast.addMod'),
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
|
||||||
|
formData.newModerator = ''
|
||||||
|
} else {
|
||||||
|
toast({
|
||||||
|
content: $t('toast.failFindUser'),
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
@@ -119,7 +135,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</EditableList>
|
</EditableList>
|
||||||
<div class="mt-auto flex gap-2 w-full">
|
<form on:submit|preventDefault={addModerator} class="mt-auto flex gap-2 w-full">
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={formData.newModerator}
|
bind:value={formData.newModerator}
|
||||||
class="w-full"
|
class="w-full"
|
||||||
@@ -130,8 +146,9 @@
|
|||||||
disabled={formData.addingModerator}
|
disabled={formData.addingModerator}
|
||||||
size="lg"
|
size="lg"
|
||||||
class="w-max flex-shrink-0"
|
class="w-max flex-shrink-0"
|
||||||
on:click={addModerator}
|
color="primary"
|
||||||
|
submit
|
||||||
>
|
>
|
||||||
<Icon slot="prefix" src={Plus} mini size="16" />Add moderator
|
<Icon slot="prefix" src={Plus} micro size="16" /> Add moderator
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</form>
|
||||||
Reference in new issue
Block a user