feat: add removal templates
This commit is contained in:
1 parent
147349d0c2
commit
9fd32aa7dd
9 files changed
+97
-10
No files matched your search
@@ -13,6 +13,9 @@
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { fullCommunityName } from '$lib/util.js'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
@@ -30,10 +33,20 @@
|
||||
: false
|
||||
|
||||
const getReplyReason = (reason: string) => {
|
||||
return `Your submission in *"${item?.post.name}"* was removed for:\n${reason}`
|
||||
if (!item) return `no template`
|
||||
|
||||
return removalTemplate($userSettings.moderation.removalReasonPreset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id
|
||||
)}`,
|
||||
postTitle: item.post.name,
|
||||
reason: reason,
|
||||
username: item.creator.name,
|
||||
})
|
||||
}
|
||||
|
||||
$: replyReason = getReplyReason(reason)
|
||||
$: replyReason = commentReason ? getReplyReason(reason) : ''
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import type {
|
||||
CommentView,
|
||||
Community,
|
||||
@@ -61,7 +62,7 @@ export function remove(item: PostView | CommentView, purge: boolean = false) {
|
||||
removing: {
|
||||
open: true,
|
||||
item: item,
|
||||
purge: purge
|
||||
purge: purge,
|
||||
},
|
||||
}))
|
||||
}
|
||||
@@ -86,3 +87,21 @@ export const amModOfAny = (me?: MyUserInfo) =>
|
||||
me && (me.moderates.length > 0 || isAdmin(me))
|
||||
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
||||
|
||||
export const removalTemplate = (
|
||||
input: string,
|
||||
content: {
|
||||
postTitle?: string
|
||||
communityLink?: string
|
||||
username?: string
|
||||
reason?: string
|
||||
}
|
||||
) => {
|
||||
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
||||
if (content.communityLink)
|
||||
input = input.replaceAll('{{community}}', content.communityLink)
|
||||
if (content.username)
|
||||
input = input.replaceAll('{{username}}', content.username)
|
||||
if (content.reason) input = input.replaceAll('{{reason}}', content.reason)
|
||||
return input
|
||||
}
|
||||
@@ -24,6 +24,8 @@
|
||||
export let previewButton: boolean = false
|
||||
export let disabled: boolean = false
|
||||
|
||||
export let beforePreview: (input: string) => string = (input) => input
|
||||
|
||||
const dispatcher = createEventDispatcher<{ confirm: string }>()
|
||||
|
||||
let textArea: HTMLTextAreaElement
|
||||
@@ -119,7 +121,7 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
||||
>
|
||||
{#if previewing}
|
||||
<div class="px-3 py-2.5 h-32 overflow-auto text-sm">
|
||||
<Markdown source={value} />
|
||||
<Markdown source={beforePreview(value)} />
|
||||
</div>
|
||||
{:else}
|
||||
<!--Toolbar-->
|
||||
|
||||
@@ -163,7 +163,7 @@
|
||||
<Menu
|
||||
let:toggleOpen
|
||||
alignment="bottom-right"
|
||||
itemsClass="h-8 md:h-9"
|
||||
itemsClass="h-8 md:h-8"
|
||||
containerClass="!max-h-[28rem]"
|
||||
>
|
||||
<button
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<aside
|
||||
class="sticky top-16 break-words flex
|
||||
flex-col gap-4 p-6 max-w-full w-80 max-h-[calc(100svh-4rem)]
|
||||
flex-col gap-4 p-6 max-w-full w-96 max-h-[calc(100svh-4rem)]
|
||||
overflow-auto text-sm border-slate-200 dark:border-zinc-800 {$$props.class}"
|
||||
>
|
||||
<slot />
|
||||
|
||||
Reference in new issue
Block a user