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'
|
||||
Reference in new issue
Block a user