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 { profile } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { ImageInput, Switch, toast } from 'mono-svelte'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
import { t } from '$lib/translations'
|
||||
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.
|
||||
@@ -18,21 +23,21 @@
|
||||
export let formData: {
|
||||
name: string
|
||||
displayName: string
|
||||
icon: FileList | null
|
||||
banner: FileList | null
|
||||
sidebar: string
|
||||
icon?: string
|
||||
banner?: string
|
||||
sidebar?: string
|
||||
nsfw: boolean
|
||||
postsLockedToModerators: boolean
|
||||
submitting: boolean
|
||||
visibility: 'Public' | 'LocalOnly'
|
||||
} = {
|
||||
name: '',
|
||||
displayName: '',
|
||||
icon: null,
|
||||
banner: null,
|
||||
sidebar: '',
|
||||
nsfw: false,
|
||||
postsLockedToModerators: false,
|
||||
submitting: false,
|
||||
visibility: 'Public',
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
@@ -42,22 +47,16 @@
|
||||
formData.submitting = true
|
||||
|
||||
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
|
||||
? await getClient().editCommunity({
|
||||
title: formData.displayName,
|
||||
description: formData.sidebar,
|
||||
nsfw: formData.nsfw,
|
||||
posting_restricted_to_mods: formData.postsLockedToModerators,
|
||||
icon: icon,
|
||||
banner: banner,
|
||||
icon: formData.icon,
|
||||
banner: formData.banner,
|
||||
community_id: edit,
|
||||
visibility: formData.visibility,
|
||||
})
|
||||
: await getClient().createCommunity({
|
||||
name: formData.name,
|
||||
@@ -65,8 +64,9 @@
|
||||
description: formData.sidebar,
|
||||
nsfw: formData.nsfw,
|
||||
posting_restricted_to_mods: formData.postsLockedToModerators,
|
||||
icon: icon,
|
||||
banner: banner,
|
||||
icon: formData.icon,
|
||||
banner: formData.banner,
|
||||
visibility: formData.visibility,
|
||||
})
|
||||
|
||||
toast({
|
||||
@@ -114,6 +114,11 @@
|
||||
|
||||
formData.submitting = false
|
||||
}
|
||||
|
||||
let uploading = {
|
||||
banner: false,
|
||||
icon: false,
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
@@ -137,18 +142,78 @@
|
||||
label={$t('form.profile.displayName')}
|
||||
bind:value={formData.displayName}
|
||||
/>
|
||||
<ImageInput label={$t('form.profile.avatar')} bind:files={formData.icon} />
|
||||
<ImageInput label={$t('form.profile.banner')} bind:files={formData.banner} />
|
||||
<div class="flex flex-row gap-4 flex-wrap *:flex-1">
|
||||
<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
|
||||
previewButton
|
||||
label={$t('routes.admin.config.sidebar')}
|
||||
bind:value={formData.sidebar}
|
||||
/>
|
||||
|
||||
<Checkbox bind:checked={formData.nsfw}>{$t('post.badges.nsfw')}</Checkbox>
|
||||
<Checkbox bind:checked={formData.postsLockedToModerators}>
|
||||
<Switch bind:checked={formData.nsfw}>{$t('post.badges.nsfw')}</Switch>
|
||||
<Switch bind:checked={formData.postsLockedToModerators}>
|
||||
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
|
||||
submit
|
||||
color="primary"
|
||||
|
||||
@@ -413,7 +413,8 @@
|
||||
"community": {
|
||||
"settings": {
|
||||
"team": "Team",
|
||||
"settings": "Settings"
|
||||
"settings": "Settings",
|
||||
"manage": "Manage"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
<script lang="ts">
|
||||
import CommunityForm from '$lib/components/lemmy/community/CommunityForm.svelte'
|
||||
import CommunityTitle from '$lib/components/lemmy/community/CommunityTitle.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
|
||||
export let data
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<CommunityTitle community={data.community.community_view.community} />
|
||||
<h1 class="font-bold text-2xl">Settings</h1>
|
||||
<Header pageHeader>
|
||||
<span>Settings</span>
|
||||
<CommunityTitle
|
||||
slot="extended"
|
||||
community={data.community.community_view.community}
|
||||
/>
|
||||
</Header>
|
||||
<CommunityForm
|
||||
edit={data.community.community_view.community.id}
|
||||
formData={{
|
||||
@@ -17,8 +23,9 @@
|
||||
postsLockedToModerators:
|
||||
data.community.community_view.community.posting_restricted_to_mods,
|
||||
sidebar: data.community.community_view.community.description ?? '',
|
||||
icon: null,
|
||||
banner: null,
|
||||
icon: data.community.community_view.community.icon,
|
||||
banner: data.community.community_view.community.banner,
|
||||
visibility: data.community.community_view.community.visibility,
|
||||
submitting: false,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import type { PageData } from './$types.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
import { t } from '$lib/translations.js'
|
||||
@@ -25,30 +25,46 @@
|
||||
formData.addingModerator = true
|
||||
|
||||
try {
|
||||
const res = await getClient().resolveObject({
|
||||
q: formData.newModerator,
|
||||
})
|
||||
|
||||
if (res.person) {
|
||||
if (Number(formData.newModerator)) {
|
||||
const addModRes = await getClient().addModToCommunity({
|
||||
added: true,
|
||||
person_id: res.person.person.id,
|
||||
person_id: Number(formData.newModerator),
|
||||
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',
|
||||
} else if (formData.newModerator) {
|
||||
const res = await getClient().resolveObject({
|
||||
q: formData.newModerator,
|
||||
})
|
||||
|
||||
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) {
|
||||
toast({
|
||||
@@ -119,7 +135,7 @@
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
<div class="mt-auto flex gap-2 w-full">
|
||||
<form on:submit|preventDefault={addModerator} class="mt-auto flex gap-2 w-full">
|
||||
<TextInput
|
||||
bind:value={formData.newModerator}
|
||||
class="w-full"
|
||||
@@ -130,8 +146,9 @@
|
||||
disabled={formData.addingModerator}
|
||||
size="lg"
|
||||
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>
|
||||
</div>
|
||||
</form>
|
||||
Reference in new issue
Block a user