feat: add admin configuration
This commit is contained in:
1 parent
f83f2f8cc8
commit
bfc4ef6ffe
14 files changed
+287
-53
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
export let checked: boolean
|
||||
const dispatcher = createEventDispatcher<{ change: boolean }>()
|
||||
</script>
|
||||
|
||||
<label class="flex flex-row items-center gap-2 cursor-pointer text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked
|
||||
on:change={() => dispatcher('change', !checked)}
|
||||
/>
|
||||
<slot />
|
||||
</label>
|
||||
@@ -1,40 +1,61 @@
|
||||
<script lang="ts">
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
|
||||
import SelectMenu from '$lib/components/input/SelectMenu.svelte'
|
||||
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
type T = $$Generic
|
||||
export let options: T[]
|
||||
export let disabled: boolean[] = []
|
||||
export let optionNames: string[] = []
|
||||
export let selected: T
|
||||
export let headless: boolean = false
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: T }>()
|
||||
|
||||
$: dispatcher('select', selected)
|
||||
$: {
|
||||
dispatcher('select', selected)
|
||||
}
|
||||
|
||||
let containerClass = `
|
||||
flex flex-row items-center w-max max-w-full
|
||||
${
|
||||
headless
|
||||
? 'pb-1'
|
||||
: 'bg-slate-100 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 rounded-lg p-1'
|
||||
}
|
||||
gap-2
|
||||
${$$props.class}
|
||||
`
|
||||
|
||||
const buttonClass = (selected: boolean) => `
|
||||
px-3 py-1.5 text-sm
|
||||
${!selected ? 'hover:bg-slate-200 hover:dark:bg-zinc-800' : ''}
|
||||
transition-colors rounded-md
|
||||
${
|
||||
selected
|
||||
? headless
|
||||
? ''
|
||||
: 'bg-slate-900 text-slate-50 dark:bg-zinc-100 dark:text-black hover:bg-slate-800 hover:dark:bg-zinc-300'
|
||||
: ''
|
||||
}
|
||||
disabled:opacity-60 disabled:pointer-events-none whitespace-nowrap
|
||||
relative
|
||||
`
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex overflow-auto flex-row items-center max-w-full w-max bg-slate-100
|
||||
rounded-lg dark:bg-zinc-900 gap-1 p-1 border border-slate-200 dark:border-zinc-800
|
||||
{$$props.class}"
|
||||
>
|
||||
<div class={containerClass}>
|
||||
{#each options.slice(0, 4) as option, index}
|
||||
<button
|
||||
class="px-3 py-1.5 text-sm rounded-md
|
||||
transition-colors
|
||||
{selected == option
|
||||
? 'bg-slate-900 text-slate-50 dark:bg-zinc-100 dark:text-black\
|
||||
hover:bg-slate-800 hover:dark:bg-zinc-300'
|
||||
: ' hover:bg-slate-200 hover:dark:bg-zinc-800'}
|
||||
disabled:opacity-60 disabled:pointer-events-none whitespace-nowrap"
|
||||
class={buttonClass(selected == option)}
|
||||
on:click={() => (selected = option)}
|
||||
disabled={disabled[index] ?? false}
|
||||
type="button"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
{#if headless && option == selected}
|
||||
<div
|
||||
class="absolute -bottom-1 left-0 w-full border-b-2 rounded-t-sm border-black dark:border-white"
|
||||
/>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
{#if options.length > 4}
|
||||
@@ -56,14 +77,3 @@
|
||||
{/if}
|
||||
</div>
|
||||
<slot {selected} />
|
||||
|
||||
<style lang="postcss">
|
||||
.custom-select {
|
||||
@apply bg-slate-50 relative;
|
||||
}
|
||||
|
||||
.custom-select select {
|
||||
appearance: none;
|
||||
@apply bg-inherit hidden;
|
||||
}
|
||||
</style>
|
||||
@@ -1,25 +1,42 @@
|
||||
<script lang="ts">
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
|
||||
import { Color } from '$lib/ui/colors'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||
import type { Alignment } from '$lib/components/ui/menu/menu.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
export let options: T[]
|
||||
export let optionNames: string[]
|
||||
export let optionNames: string[] = []
|
||||
export let selected: T
|
||||
export let label: string | undefined = undefined
|
||||
export let alignment: Alignment = 'bottom-left'
|
||||
|
||||
let open = false
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: T }>()
|
||||
</script>
|
||||
|
||||
<Menu let:toggleOpen>
|
||||
<Button slot="button" on:click={toggleOpen} color="tertiary" size="square-md">
|
||||
<slot />
|
||||
</Button>
|
||||
{#if label}
|
||||
<div class="block font-bold text-sm w-max">{label}</div>
|
||||
{/if}
|
||||
<Menu let:toggleOpen {alignment}>
|
||||
<div slot="button" class="w-max relative">
|
||||
<Button on:click={toggleOpen} color="secondary">
|
||||
<slot>
|
||||
{optionNames[options.findIndex((o) => selected == o)] || selected}
|
||||
</slot>
|
||||
</Button>
|
||||
</div>
|
||||
{#each options as option, index}
|
||||
<MenuButton on:click={() => (selected = option)}>
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
selected = option
|
||||
dispatcher('select', option)
|
||||
}}
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import {
|
||||
amModOfAny,
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import Logo from '$lib/components/ui/Logo.svelte'
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
@@ -17,6 +20,7 @@
|
||||
Beaker,
|
||||
Bookmark,
|
||||
Cog6Tooth,
|
||||
CommandLine,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
Inbox,
|
||||
@@ -82,10 +86,22 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 py-2 px-2">
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<Button
|
||||
href="/admin"
|
||||
aria-label="Admin"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0
|
||||
hover:text-inherit
|
||||
hover:bg-slate-200 hover:dark:bg-zinc-900 relative"
|
||||
>
|
||||
<Icon src={CommandLine} mini size="16" slot="icon" />
|
||||
<span class="hidden md:inline">Admin</span>
|
||||
</Button>
|
||||
{/if}
|
||||
{#if amModOfAny($profile?.user)}
|
||||
<Button
|
||||
href="/moderation"
|
||||
label="Search"
|
||||
aria-label="Moderation"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 items-center justify-center
|
||||
dark:text-zinc-300 text-slate-700 hover:text-inherit
|
||||
hover:bg-slate-200 hover:dark:bg-zinc-900 relative"
|
||||
@@ -95,13 +111,13 @@
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
{/if}
|
||||
<ShieldIcon width={15} />
|
||||
<ShieldIcon filled width={15} />
|
||||
<span class="hidden md:inline">Reports</span>
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
href="/search"
|
||||
label="Search"
|
||||
aria-label="Search"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 items-center justify-center
|
||||
dark:text-zinc-300 text-slate-700 hover:text-inherit hover:bg-slate-200 hover:dark:bg-zinc-900"
|
||||
>
|
||||
@@ -110,7 +126,7 @@
|
||||
</Button>
|
||||
<Button
|
||||
href="/communities"
|
||||
label="Communities"
|
||||
aria-label="Communities"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 items-center justify-center
|
||||
dark:text-zinc-300 text-slate-700 hover:text-inherit hover:bg-slate-200 hover:dark:bg-zinc-900"
|
||||
>
|
||||
@@ -121,7 +137,7 @@
|
||||
<Button
|
||||
color="primary"
|
||||
slot="button"
|
||||
label="Create"
|
||||
aria-label="Create"
|
||||
on:click={toggleOpen}
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0"
|
||||
>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { Alignment } from '$lib/components/ui/menu/menu.js'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { scale } from 'svelte/transition'
|
||||
|
||||
@@ -11,14 +12,6 @@
|
||||
|
||||
export let absolute = false
|
||||
|
||||
type Alignment =
|
||||
| 'top-right'
|
||||
| 'top-left'
|
||||
| 'bottom-right'
|
||||
| 'bottom-left'
|
||||
| 'bottom-center'
|
||||
| 'top-center'
|
||||
|
||||
export let alignment: Alignment = 'bottom-left'
|
||||
|
||||
let element: any
|
||||
@@ -32,7 +25,7 @@
|
||||
case 'bottom-left':
|
||||
return 'top-[100%] origin-top-left'
|
||||
case 'top-left':
|
||||
return 'top-[100%] left-0 origin-top-left'
|
||||
return 'bottom-[100%] left-0 origin-bottom-left'
|
||||
case 'bottom-right':
|
||||
return 'top-[100%] right-0 origin-top-right'
|
||||
case 'top-center':
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export type Alignment =
|
||||
| 'top-right'
|
||||
| 'top-left'
|
||||
| 'bottom-right'
|
||||
| 'bottom-left'
|
||||
| 'bottom-center'
|
||||
| 'top-center'
|
||||
@@ -0,0 +1,18 @@
|
||||
<script>
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<MultiSelect
|
||||
headless
|
||||
options={['/admin/config', '/admin/applications']}
|
||||
optionNames={['Configuration', 'Applications']}
|
||||
selected={$page.url.pathname}
|
||||
on:select={(e) => {
|
||||
goto(e.detail)
|
||||
}}
|
||||
/>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { get } from 'svelte/store'
|
||||
import { getClient, site as siteStore } from '$lib/lemmy.js'
|
||||
|
||||
export async function load({ fetch }) {
|
||||
if (!get(profile)) return
|
||||
let { jwt } = get(profile)!
|
||||
let site = get(siteStore)
|
||||
|
||||
if (!site) {
|
||||
const res = await getClient(undefined, fetch).getSite({
|
||||
auth: jwt,
|
||||
})
|
||||
|
||||
site = res
|
||||
}
|
||||
|
||||
return {
|
||||
site: site,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
hey
|
||||
Whitespace-only changes.
@@ -0,0 +1,129 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||
import SelectMenu from '$lib/components/input/SelectMenu.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { EditSite } from 'lemmy-js-client'
|
||||
import type { PageData } from './$types.js'
|
||||
|
||||
export let data: PageData
|
||||
|
||||
const site = {
|
||||
...data.site?.site_view.site,
|
||||
}
|
||||
|
||||
const local_site = {
|
||||
...data.site?.site_view.local_site,
|
||||
}
|
||||
const h = {
|
||||
fart: 'hey',
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
saving = true
|
||||
const { jwt } = $profile
|
||||
|
||||
try {
|
||||
await getClient().editSite({
|
||||
auth: jwt,
|
||||
name: site.name,
|
||||
description: site.description,
|
||||
sidebar: site.sidebar,
|
||||
legal_information: local_site.legal_information,
|
||||
enable_downvotes: local_site.enable_downvotes,
|
||||
enable_nsfw: local_site.enable_nsfw,
|
||||
registration_mode: local_site.registration_mode,
|
||||
community_creation_admin_only: local_site.community_creation_admin_only,
|
||||
require_email_verification: local_site.require_email_verification,
|
||||
})
|
||||
toast({
|
||||
content: 'Updated your site.',
|
||||
type: 'success',
|
||||
})
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
saving = false
|
||||
}
|
||||
|
||||
let saving = false
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Administration</title>
|
||||
</svelte:head>
|
||||
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={save}>
|
||||
<h1 class="font-bold text-2xl">Site configuration</h1>
|
||||
{#if site}
|
||||
<TextInput bind:value={site.name} label="Name" />
|
||||
<TextInput bind:value={site.description} label="Description" />
|
||||
<MarkdownEditor previewButton bind:value={site.sidebar} label="Sidebar" />
|
||||
{/if}
|
||||
{#if local_site}
|
||||
<MarkdownEditor
|
||||
previewButton
|
||||
bind:value={local_site.legal_information}
|
||||
label="Legal"
|
||||
/>
|
||||
<Checkbox
|
||||
checked={local_site.enable_downvotes ?? true}
|
||||
on:change={(e) => {
|
||||
local_site.enable_downvotes = !local_site.enable_downvotes
|
||||
}}
|
||||
>
|
||||
Enable downvotes
|
||||
</Checkbox>
|
||||
<Checkbox
|
||||
checked={local_site.enable_nsfw ?? true}
|
||||
on:change={(e) => {
|
||||
local_site.enable_nsfw = !local_site.enable_nsfw
|
||||
}}
|
||||
>
|
||||
Enable NSFW
|
||||
</Checkbox>
|
||||
<SelectMenu
|
||||
label="Registration mode"
|
||||
alignment="top-left"
|
||||
options={['Closed', 'RequireApplication', 'Open']}
|
||||
optionNames={['Closed', 'Require Application', 'Open Registration']}
|
||||
selected={local_site.registration_mode ?? 'Open'}
|
||||
on:select={(e) => {
|
||||
// @ts-ignore
|
||||
local_site.registration_mode = e.detail
|
||||
}}
|
||||
/>
|
||||
<Checkbox
|
||||
checked={local_site.community_creation_admin_only ?? true}
|
||||
on:change={(e) => {
|
||||
local_site.community_creation_admin_only =
|
||||
!local_site.community_creation_admin_only
|
||||
}}
|
||||
>
|
||||
Only admins can create communities
|
||||
</Checkbox>
|
||||
<Checkbox
|
||||
checked={local_site.require_email_verification ?? true}
|
||||
on:change={(e) => {
|
||||
local_site.require_email_verification =
|
||||
!local_site.require_email_verification
|
||||
}}
|
||||
>
|
||||
Require email verification
|
||||
</Checkbox>
|
||||
{/if}
|
||||
<Button color="primary" size="lg" loading={saving} disabled={saving} submit>
|
||||
Save
|
||||
</Button>
|
||||
</form>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient, site as siteStore } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ fetch }) {}
|
||||
@@ -5,11 +5,13 @@
|
||||
:root {
|
||||
@apply bg-slate-50 dark:bg-zinc-950 text-slate-900
|
||||
dark:text-zinc-100 !important;
|
||||
accent-color: #000;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
accent-color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user