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 { profile } from '$lib/auth.svelte.js'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { getClient } from '$lib/lemmy.svelte'
|
import { getClient } from '$lib/lemmy.svelte'
|
||||||
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
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 {
|
import {
|
||||||
ArrowsUpDown,
|
ArrowsUpDown,
|
||||||
Fire,
|
Fire,
|
||||||
@@ -17,23 +19,19 @@
|
|||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
||||||
import ShieldIcon from './ShieldIcon.svelte'
|
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
item: PostView | CommentView
|
item: PostView | CommentView
|
||||||
|
target: Snippet<[boolean]>
|
||||||
}
|
}
|
||||||
|
|
||||||
let { item = $bindable(), ...rest }: Props = $props()
|
let { item = $bindable(), target: passedTarget }: Props = $props()
|
||||||
|
|
||||||
let locking = $state(false)
|
let acting = $state(false)
|
||||||
let pinning = $state(false)
|
|
||||||
|
|
||||||
let acting = $derived(locking || pinning)
|
|
||||||
|
|
||||||
async function lock(lock: boolean) {
|
async function lock(lock: boolean) {
|
||||||
if (!profile.current?.jwt || !isPostView(item)) return
|
if (!profile.current?.jwt || !isPostView(item)) return
|
||||||
locking = true
|
acting = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().lockPost({
|
await getClient().lockPost({
|
||||||
@@ -49,13 +47,13 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
locking = false
|
acting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||||
if (!profile.current?.jwt || !isPostView(item)) return
|
if (!profile.current?.jwt || !isPostView(item)) return
|
||||||
|
|
||||||
pinning = true
|
acting = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().featurePost({
|
await getClient().featurePost({
|
||||||
@@ -72,21 +70,13 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pinning = false
|
acting = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Menu placement="bottom-end">
|
<Menu placement="bottom-end">
|
||||||
{#snippet target()}
|
{#snippet target()}
|
||||||
<Button
|
{@render passedTarget(acting)}
|
||||||
class="hover:text-green-500!"
|
|
||||||
size="square-md"
|
|
||||||
color="ghost"
|
|
||||||
loading={acting}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
<ShieldIcon filled width={16} />
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||||
<MenuDivider>
|
<MenuDivider>
|
||||||
@@ -99,8 +89,7 @@
|
|||||||
<MenuButton
|
<MenuButton
|
||||||
color="warning-subtle"
|
color="warning-subtle"
|
||||||
onclick={() => lock(!item.post.locked)}
|
onclick={() => lock(!item.post.locked)}
|
||||||
loading={locking}
|
loading={acting}
|
||||||
disabled={locking}
|
|
||||||
>
|
>
|
||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||||
@@ -112,8 +101,7 @@
|
|||||||
color="success-subtle"
|
color="success-subtle"
|
||||||
onclick={() =>
|
onclick={() =>
|
||||||
pin(isPostView(item) ? !item.post.featured_community : false)}
|
pin(isPostView(item) ? !item.post.featured_community : false)}
|
||||||
loading={pinning}
|
loading={acting}
|
||||||
disabled={pinning}
|
|
||||||
>
|
>
|
||||||
<Icon src={Megaphone} size="16" mini />
|
<Icon src={Megaphone} size="16" mini />
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
isAdmin,
|
isAdmin,
|
||||||
report,
|
report,
|
||||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
} 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 TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date'
|
import { publishedToDate } from '$lib/components/util/date'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
@@ -46,6 +45,7 @@
|
|||||||
Newspaper,
|
Newspaper,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
Share,
|
Share,
|
||||||
|
ShieldCheck,
|
||||||
Trash,
|
Trash,
|
||||||
UserCircle,
|
UserCircle,
|
||||||
XMark,
|
XMark,
|
||||||
@@ -161,14 +161,21 @@
|
|||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||||
<ModerationMenu
|
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
|
||||||
size="custom"
|
<ModerationMenu bind:item={post}>
|
||||||
color="ghost"
|
{#snippet target(acting)}
|
||||||
rounding="pill"
|
<Button
|
||||||
class={buttonSquare}
|
color="ghost"
|
||||||
bind:item={post}
|
rounding="pill"
|
||||||
community={post.community}
|
loading={acting}
|
||||||
/>
|
class={buttonSquare}
|
||||||
|
size="custom"
|
||||||
|
>
|
||||||
|
<Icon src={ShieldCheck} size="18" mini />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</ModerationMenu>
|
||||||
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if profile.current?.jwt}
|
{#if profile.current?.jwt}
|
||||||
|
|||||||
@@ -123,14 +123,14 @@
|
|||||||
role={href ? 'link' : 'button'}
|
role={href ? 'link' : 'button'}
|
||||||
{href}
|
{href}
|
||||||
{...rest}
|
{...rest}
|
||||||
tabindex={disabled ? -1 : undefined}
|
tabindex={disabled || loading ? -1 : undefined}
|
||||||
class={[
|
class={[
|
||||||
loading ? buttonColor.secondary : buttonColor[color],
|
loading ? buttonColor.secondary : buttonColor[color],
|
||||||
buttonSize[size],
|
buttonSize[size],
|
||||||
buttonRounding[rounding],
|
buttonRounding[rounding],
|
||||||
buttonShadow[shadow],
|
buttonShadow[shadow],
|
||||||
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none',
|
'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'
|
alignment == 'center'
|
||||||
? 'origin-center'
|
? 'origin-center'
|
||||||
: alignment == 'left'
|
: 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 { default as Button } from './button/Button.svelte'
|
||||||
export { buttonColor, buttonSize, buttonShadow } from './button/Button.svelte'
|
export { buttonColor, buttonSize, buttonShadow } from './button/Button.svelte'
|
||||||
export { default as Codeblock } from './code/Codeblock.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 Spinner } from './loader/Spinner.svelte'
|
||||||
export { default as Material } from './materials/Material.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 Checkbox } from './forms/Checkbox.svelte'
|
||||||
export { default as Switch } from './forms/Switch.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 Popover } from './popover/Popover.svelte'
|
||||||
export { default as Menu } from './popover/Menu.svelte'
|
export { default as Menu } from './popover/Menu.svelte'
|
||||||
export { default as MenuDivider } from './popover/MenuDivider.svelte'
|
export { default as MenuDivider } from './popover/MenuDivider.svelte'
|
||||||
|
|||||||
Reference in new issue
Block a user