migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
@@ -9,17 +11,25 @@
|
||||
import { t } from '$lib/translations'
|
||||
import CommunityLink from '../community/CommunityLink.svelte'
|
||||
|
||||
export let open = false
|
||||
let item: Person | undefined
|
||||
export { item as user }
|
||||
export let community: Community | undefined
|
||||
export let banned: boolean
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person | undefined
|
||||
community: Community | undefined
|
||||
banned: boolean
|
||||
}
|
||||
|
||||
let reason = ''
|
||||
let deleteData = false
|
||||
let expires = ''
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user: item = $bindable(),
|
||||
community,
|
||||
banned,
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let reason = $state('')
|
||||
let deleteData = $state(false)
|
||||
let expires = $state('')
|
||||
|
||||
let loading = $state(false)
|
||||
|
||||
// hack due to svelte's reactive declarations
|
||||
const resetReason = () => {
|
||||
@@ -28,7 +38,9 @@
|
||||
expires = ''
|
||||
}
|
||||
|
||||
$: if (item) resetReason()
|
||||
run(() => {
|
||||
if (item) resetReason()
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!item || !$profile?.user || !$profile?.jwt) return
|
||||
@@ -105,7 +117,7 @@
|
||||
title={banned ? $t('moderation.ban.unbanning') : $t('moderation.ban.banning')}
|
||||
>
|
||||
{#if item}
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={submit}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(submit)}>
|
||||
<div class="flex items-center gap-1">
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<span class="font-bold">{item.name}</span>
|
||||
@@ -121,9 +133,9 @@
|
||||
{#if !banned}
|
||||
<Checkbox bind:checked={deleteData}>
|
||||
{$t('moderation.ban.deleteData')}
|
||||
<svelte:fragment slot="description">
|
||||
{#snippet description()}
|
||||
{$t('moderation.ban.warning')}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</Checkbox>
|
||||
<TextInput
|
||||
bind:value={expires}
|
||||
|
||||
@@ -14,19 +14,25 @@
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||
<Button
|
||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
slot="target"
|
||||
color="tertiary"
|
||||
{...$$restProps}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
||||
@@ -36,7 +42,9 @@
|
||||
{/if}
|
||||
</MenuDivider>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{/snippet}
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
? $t('moderation.restore')
|
||||
@@ -52,7 +60,9 @@
|
||||
on:click={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{/snippet}
|
||||
{item.creator_banned_from_community
|
||||
? $t('moderation.ban.unbanFromCommunity')
|
||||
: $t('moderation.ban.banFromCommunity')}
|
||||
@@ -67,12 +77,14 @@
|
||||
await feature(
|
||||
!item.comment.distinguished,
|
||||
item.comment,
|
||||
$profile.jwt
|
||||
$profile.jwt,
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Megaphone} size="16" micro />
|
||||
{/snippet}
|
||||
{item.comment.distinguished
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
@@ -83,7 +95,9 @@
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -18,12 +18,17 @@
|
||||
import { t } from '$lib/translations'
|
||||
import ShieldIcon from './ShieldIcon.svelte'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let locking = false
|
||||
let pinning = false
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
|
||||
$: acting = locking || pinning
|
||||
let locking = $state(false)
|
||||
let pinning = $state(false)
|
||||
|
||||
let acting = $derived(locking || pinning)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!$profile?.jwt || !isPostView(item)) return
|
||||
@@ -71,16 +76,17 @@
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
<Button
|
||||
class="hover:!text-green-500"
|
||||
slot="target"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...$$restProps}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="hover:!text-green-500"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
||||
@@ -95,12 +101,9 @@
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
>
|
||||
<Icon
|
||||
src={item.post.locked ? LockOpen : LockClosed}
|
||||
size="16"
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||
{/snippet}
|
||||
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
||||
</MenuButton>
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { Select, Switch, toast } from 'mono-svelte'
|
||||
@@ -16,21 +18,31 @@
|
||||
import { Button, Checkbox, Modal } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
export let purge: boolean = false
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | undefined
|
||||
purge?: boolean
|
||||
}
|
||||
|
||||
let reason = ''
|
||||
let commentReason: boolean = false
|
||||
let privateMessage: boolean = false
|
||||
let loading = false
|
||||
let preset = $userSettings.moderation.presets[0]?.content ?? ''
|
||||
let {
|
||||
open = $bindable(),
|
||||
item = $bindable(undefined),
|
||||
purge = false,
|
||||
}: Props = $props()
|
||||
|
||||
$: removed = item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false
|
||||
let reason = $state('')
|
||||
let commentReason: boolean = $state(false)
|
||||
let privateMessage: boolean = $state(false)
|
||||
let loading = $state(false)
|
||||
let preset = $state($userSettings.moderation.presets[0]?.content ?? '')
|
||||
|
||||
let removed = $derived(
|
||||
item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false,
|
||||
)
|
||||
|
||||
const getReplyReason = (reason: string, preset: string) => {
|
||||
if (!item) return `no template`
|
||||
@@ -38,7 +50,7 @@
|
||||
return removalTemplate(preset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id
|
||||
item!.community.actor_id,
|
||||
)}`,
|
||||
postTitle: item.post.name,
|
||||
reason: reason,
|
||||
@@ -46,7 +58,10 @@
|
||||
})
|
||||
}
|
||||
|
||||
$: replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
let replyReason
|
||||
run(() => {
|
||||
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
})
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
@@ -151,11 +166,11 @@
|
||||
commentReason = false
|
||||
}
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
@@ -168,7 +183,7 @@
|
||||
>
|
||||
{#if item}
|
||||
<form
|
||||
on:submit|preventDefault={remove}
|
||||
onsubmit={preventDefault(remove)}
|
||||
class="flex flex-col gap-4 list-none"
|
||||
>
|
||||
{#if isCommentView(item)}
|
||||
@@ -212,16 +227,18 @@
|
||||
placeholder={replyReason}
|
||||
rows={3}
|
||||
>
|
||||
<div class="flex justify-between items-end mb-1" slot="label">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each $userSettings.moderation.presets as preset}
|
||||
<option value={preset.content}>
|
||||
{preset.title}
|
||||
</option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{#snippet label()}
|
||||
<div class="flex justify-between items-end mb-1">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each $userSettings.moderation.presets as preset}
|
||||
<option value={preset.content}>
|
||||
{preset.title}
|
||||
</option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{/snippet}
|
||||
</MarkdownEditor>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -233,7 +250,9 @@
|
||||
disabled={loading}
|
||||
submit
|
||||
>
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" />
|
||||
{/snippet}
|
||||
{#if purge}
|
||||
{$t('admin.purge')}
|
||||
{:else}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { toast } from 'mono-svelte'
|
||||
@@ -16,24 +18,27 @@
|
||||
import { t } from '$lib/translations'
|
||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | PrivateMessageView | undefined =
|
||||
undefined
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | PrivateMessageView | undefined
|
||||
}
|
||||
|
||||
let { open = $bindable(), item = undefined }: Props = $props()
|
||||
|
||||
const isComment = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is CommentView => 'comment' in item
|
||||
|
||||
const isPost = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PostView => !isComment(item) && 'post' in item
|
||||
|
||||
const isPrivateMessage = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
||||
|
||||
let loading = false
|
||||
let reason = ''
|
||||
let loading = $state(false)
|
||||
let reason = $state('')
|
||||
|
||||
async function report() {
|
||||
if (!item || !$profile?.jwt || reason == '') return
|
||||
@@ -70,15 +75,15 @@
|
||||
|
||||
const resetText = () => (reason = '')
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('moderation.reportModal.title')}>
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={report}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(report)}>
|
||||
{#if item}
|
||||
<div class="pointer-events-none list-none">
|
||||
{#if isComment(item)}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let width: number = 16
|
||||
export let filled: boolean = false
|
||||
interface Props {
|
||||
width?: number
|
||||
filled?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let { width = 16, filled = false, class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if filled}
|
||||
|
||||
@@ -106,7 +106,7 @@ export const removalTemplate = (
|
||||
communityLink?: string
|
||||
username?: string
|
||||
reason?: string
|
||||
}
|
||||
},
|
||||
) => {
|
||||
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
||||
if (content.communityLink)
|
||||
|
||||
Reference in new issue
Block a user