feat: add multiple presets
This commit is contained in:
1 parent
78022bee5e
commit
d6edfaca36
6 files changed
+120
-27
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { Select, toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
@@ -23,6 +23,7 @@
|
||||
let commentReason: boolean = false
|
||||
let privateMessage: boolean = false
|
||||
let loading = false
|
||||
let preset = $userSettings.moderation.presets[0]?.content ?? ''
|
||||
|
||||
$: removed = item
|
||||
? isCommentView(item)
|
||||
@@ -30,10 +31,10 @@
|
||||
: item.post.removed
|
||||
: false
|
||||
|
||||
const getReplyReason = (reason: string) => {
|
||||
const getReplyReason = (reason: string, preset: string) => {
|
||||
if (!item) return `no template`
|
||||
|
||||
return removalTemplate($userSettings.moderation.removalReasonPreset, {
|
||||
return removalTemplate(preset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id
|
||||
@@ -44,7 +45,7 @@
|
||||
})
|
||||
}
|
||||
|
||||
$: replyReason = commentReason ? getReplyReason(reason) : ''
|
||||
$: replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
@@ -212,8 +213,18 @@
|
||||
bind:value={replyReason}
|
||||
placeholder={replyReason}
|
||||
rows={3}
|
||||
label="Reply"
|
||||
/>
|
||||
>
|
||||
<div class="flex justify-between items-end mb-1" slot="label">
|
||||
Reply
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each $userSettings.moderation.presets as preset}
|
||||
<option value={preset.content}>
|
||||
{preset.title}
|
||||
</option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
</MarkdownEditor>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -110,9 +110,13 @@
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
{#if label}
|
||||
{#if label || $$slots.label}
|
||||
<Label>
|
||||
{label}
|
||||
{#if label}
|
||||
{label}
|
||||
{:else if $$slots.label}
|
||||
<slot name="label" />
|
||||
{/if}
|
||||
</Label>
|
||||
{/if}
|
||||
<div
|
||||
|
||||
+28
-2
@@ -17,6 +17,11 @@ const toBool = (str: string | undefined) => {
|
||||
return str.toLowerCase() === 'true'
|
||||
}
|
||||
|
||||
interface Preset {
|
||||
title?: string
|
||||
content: string
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
expandableImages: boolean
|
||||
// should have been named "fade" read posts
|
||||
@@ -52,7 +57,7 @@ interface Settings {
|
||||
displayNames: boolean
|
||||
nsfwBlur: boolean
|
||||
moderation: {
|
||||
removalReasonPreset: string
|
||||
presets: Preset[]
|
||||
}
|
||||
newVote: boolean
|
||||
randomPlaceholders: boolean
|
||||
@@ -94,7 +99,12 @@ export const defaultSettings: Settings = {
|
||||
displayNames: toBool(env.PUBLIC_DISPLAY_NAMES) ?? true,
|
||||
nsfwBlur: toBool(env.PUBLIC_NSFW_BLUR) ?? true,
|
||||
moderation: {
|
||||
removalReasonPreset: `Your submission in *"{{post}}"* was removed for {{reason}}.`,
|
||||
presets: [
|
||||
{
|
||||
title: 'Preset 1',
|
||||
content: `Your submission in *"{{post}}"* was removed for {{reason}}.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false,
|
||||
randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true,
|
||||
@@ -110,11 +120,27 @@ export const defaultSettings: Settings = {
|
||||
|
||||
export const userSettings = writable(defaultSettings)
|
||||
|
||||
const migrate = (settings: any): Settings => {
|
||||
if (typeof settings.moderation.removalReasonPreset == 'string') {
|
||||
settings.moderation.presets = [
|
||||
{
|
||||
title: 'Preset 1',
|
||||
content: settings.moderation.removalReasonPreset,
|
||||
},
|
||||
]
|
||||
settings.moderation.removalReasonPreset = undefined
|
||||
}
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
if (typeof window != 'undefined') {
|
||||
let oldUserSettings = JSON.parse(
|
||||
localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
|
||||
)
|
||||
|
||||
oldUserSettings = migrate(oldUserSettings)
|
||||
|
||||
userSettings.set({ ...defaultSettings, ...oldUserSettings })
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user