impr: extrapolate moderationmenu into snippet
This commit is contained in:
7 files changed
+31
-182
No files matched your search
@@ -2,9 +2,11 @@
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import { Button, Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
Fire,
|
||||
@@ -17,23 +19,19 @@
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
||||
import ShieldIcon from './ShieldIcon.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
target: Snippet<[boolean]>
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
let { item = $bindable(), target: passedTarget }: Props = $props()
|
||||
|
||||
let locking = $state(false)
|
||||
let pinning = $state(false)
|
||||
|
||||
let acting = $derived(locking || pinning)
|
||||
let acting = $state(false)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
locking = true
|
||||
acting = true
|
||||
|
||||
try {
|
||||
await getClient().lockPost({
|
||||
@@ -49,13 +47,13 @@
|
||||
})
|
||||
}
|
||||
|
||||
locking = false
|
||||
acting = false
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
|
||||
pinning = true
|
||||
acting = true
|
||||
|
||||
try {
|
||||
await getClient().featurePost({
|
||||
@@ -72,21 +70,13 @@
|
||||
})
|
||||
}
|
||||
|
||||
pinning = false
|
||||
acting = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="hover:text-green-500!"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{@render passedTarget(acting)}
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider>
|
||||
@@ -99,8 +89,7 @@
|
||||
<MenuButton
|
||||
color="warning-subtle"
|
||||
onclick={() => lock(!item.post.locked)}
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
loading={acting}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||
@@ -112,8 +101,7 @@
|
||||
color="success-subtle"
|
||||
onclick={() =>
|
||||
pin(isPostView(item) ? !item.post.featured_community : false)}
|
||||
loading={pinning}
|
||||
disabled={pinning}
|
||||
loading={acting}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" mini />
|
||||
<div
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
isAdmin,
|
||||
report,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
@@ -46,6 +45,7 @@
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
Share,
|
||||
ShieldCheck,
|
||||
Trash,
|
||||
UserCircle,
|
||||
XMark,
|
||||
@@ -161,14 +161,21 @@
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
<ModerationMenu
|
||||
size="custom"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
bind:item={post}
|
||||
community={post.community}
|
||||
/>
|
||||
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
|
||||
<ModerationMenu bind:item={post}>
|
||||
{#snippet target(acting)}
|
||||
<Button
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
loading={acting}
|
||||
class={buttonSquare}
|
||||
size="custom"
|
||||
>
|
||||
<Icon src={ShieldCheck} size="18" mini />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</ModerationMenu>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.jwt}
|
||||
|
||||
@@ -123,14 +123,14 @@
|
||||
role={href ? 'link' : 'button'}
|
||||
{href}
|
||||
{...rest}
|
||||
tabindex={disabled ? -1 : undefined}
|
||||
tabindex={disabled || loading ? -1 : undefined}
|
||||
class={[
|
||||
loading ? buttonColor.secondary : buttonColor[color],
|
||||
buttonSize[size],
|
||||
buttonRounding[rounding],
|
||||
buttonShadow[shadow],
|
||||
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none',
|
||||
disabled && 'pointer-events-none opacity-50 shadow-none',
|
||||
disabled || (loading && 'pointer-events-none opacity-50 shadow-none'),
|
||||
alignment == 'center'
|
||||
? 'origin-center'
|
||||
: alignment == 'left'
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '../index.js'
|
||||
import { Check, Icon, Clipboard } from 'svelte-hero-icons'
|
||||
import { scale } from 'svelte/transition'
|
||||
|
||||
let copied = $state(false)
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* Show a copy button.
|
||||
*/
|
||||
value: string
|
||||
copy?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { value, copy = true, class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="px-4 py-1 flex justify-between max-w-full box-border bg-slate-100 dark:bg-zinc-950 items-center gap-4 rounded-md border dark:border-zinc-800
|
||||
{clazz}"
|
||||
>
|
||||
<pre class="overflow-auto max-w-full whitespace-nowrap w-max">
|
||||
{value}
|
||||
</pre>
|
||||
{#if copy}
|
||||
<Button
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
aria-label="Copy"
|
||||
onclick={() => {
|
||||
copied = true
|
||||
navigator.clipboard.writeText(value)
|
||||
setTimeout(() => (copied = false), 2000)
|
||||
}}
|
||||
>
|
||||
<div class="relative w-full h-full grid place-items-center">
|
||||
{#if !copied}
|
||||
<div
|
||||
transition:scale={{ opacity: 0, start: 0.3 }}
|
||||
class="top-0 left-0"
|
||||
style="grid-row: 1; grid-column: 1;"
|
||||
>
|
||||
<Icon src={Clipboard} size="18" mini />
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
transition:scale={{ opacity: 0, start: 0.3 }}
|
||||
class="top-0 left-0"
|
||||
style="grid-row: 1; grid-column: 1;"
|
||||
>
|
||||
<Icon src={Check} size="18" mini />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1,58 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
|
||||
const bubble = createBubbler()
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
interface Props {
|
||||
value: T
|
||||
group: T
|
||||
inlineDescription?: boolean
|
||||
id?: string
|
||||
disabled?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
description?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
value,
|
||||
group = $bindable(),
|
||||
inlineDescription = false,
|
||||
id = generateID(),
|
||||
disabled = false,
|
||||
children,
|
||||
description,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="font-normal cursor-pointer text-sm flex flex-row items-baseline gap-2"
|
||||
>
|
||||
<input
|
||||
{...rest}
|
||||
{id}
|
||||
type="radio"
|
||||
bind:group
|
||||
{value}
|
||||
onblur={bubble('blur-sm')}
|
||||
onchange={bubble('change')}
|
||||
{disabled}
|
||||
class="cursor-pointer disabled:cursor-not-allowed peer disabled:opacity-50"
|
||||
/>
|
||||
<label
|
||||
for={id}
|
||||
class="inline-flex {inlineDescription
|
||||
? 'flex-row'
|
||||
: 'flex-col'} cursor-pointer peer-disabled:cursor-not-allowed font-medium gap-1 peer-disabled:opacity-50"
|
||||
>
|
||||
{@render children?.()}
|
||||
{#if description}
|
||||
<span class="font-normal text-slate-600 dark:text-zinc-400">
|
||||
{@render description?.()}
|
||||
</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
@@ -1,25 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
interface Props {
|
||||
group?: string
|
||||
row?: boolean
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[{ group: string }]>
|
||||
}
|
||||
|
||||
let {
|
||||
group = generateID(),
|
||||
row = false,
|
||||
class: clazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<div
|
||||
class="flex {row ? 'flex-row flex-wrap' : 'flex-col'} gap-4 {clazz || ''}"
|
||||
>
|
||||
{@render children?.({ group })}
|
||||
</div>
|
||||
</div>
|
||||
@@ -3,7 +3,6 @@
|
||||
export { default as Button } from './button/Button.svelte'
|
||||
export { buttonColor, buttonSize, buttonShadow } from './button/Button.svelte'
|
||||
export { default as Codeblock } from './code/Codeblock.svelte'
|
||||
export { default as Snippet } from './code/Snippet.svelte'
|
||||
export { default as Spinner } from './loader/Spinner.svelte'
|
||||
export { default as Material } from './materials/Material.svelte'
|
||||
|
||||
@@ -18,9 +17,6 @@ export { default as ImageInput } from './forms/ImageInput.svelte'
|
||||
export { default as Checkbox } from './forms/Checkbox.svelte'
|
||||
export { default as Switch } from './forms/Switch.svelte'
|
||||
|
||||
export { default as Radio } from './forms/Radio.svelte'
|
||||
export { default as RadioGroup } from './forms/RadioGroup.svelte'
|
||||
|
||||
export { default as Popover } from './popover/Popover.svelte'
|
||||
export { default as Menu } from './popover/Menu.svelte'
|
||||
export { default as MenuDivider } from './popover/MenuDivider.svelte'
|
||||
|
||||
Reference in new issue
Block a user