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
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "1.11.4",
|
"version": "1.12.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.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 { getClient } from '$lib/lemmy.js'
|
||||||
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'
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
let commentReason: boolean = false
|
let commentReason: boolean = false
|
||||||
let privateMessage: boolean = false
|
let privateMessage: boolean = false
|
||||||
let loading = false
|
let loading = false
|
||||||
|
let preset = $userSettings.moderation.presets[0]?.content ?? ''
|
||||||
|
|
||||||
$: removed = item
|
$: removed = item
|
||||||
? isCommentView(item)
|
? isCommentView(item)
|
||||||
@@ -30,10 +31,10 @@
|
|||||||
: item.post.removed
|
: item.post.removed
|
||||||
: false
|
: false
|
||||||
|
|
||||||
const getReplyReason = (reason: string) => {
|
const getReplyReason = (reason: string, preset: string) => {
|
||||||
if (!item) return `no template`
|
if (!item) return `no template`
|
||||||
|
|
||||||
return removalTemplate($userSettings.moderation.removalReasonPreset, {
|
return removalTemplate(preset, {
|
||||||
communityLink: `!${fullCommunityName(
|
communityLink: `!${fullCommunityName(
|
||||||
item!.community.name,
|
item!.community.name,
|
||||||
item!.community.actor_id
|
item!.community.actor_id
|
||||||
@@ -44,7 +45,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$: replyReason = commentReason ? getReplyReason(reason) : ''
|
$: replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||||
|
|
||||||
async function remove() {
|
async function remove() {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
@@ -212,8 +213,18 @@
|
|||||||
bind:value={replyReason}
|
bind:value={replyReason}
|
||||||
placeholder={replyReason}
|
placeholder={replyReason}
|
||||||
rows={3}
|
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}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -110,9 +110,13 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
{#if label}
|
{#if label || $$slots.label}
|
||||||
<Label>
|
<Label>
|
||||||
{label}
|
{#if label}
|
||||||
|
{label}
|
||||||
|
{:else if $$slots.label}
|
||||||
|
<slot name="label" />
|
||||||
|
{/if}
|
||||||
</Label>
|
</Label>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
|
|||||||
+28
-2
@@ -17,6 +17,11 @@ const toBool = (str: string | undefined) => {
|
|||||||
return str.toLowerCase() === 'true'
|
return str.toLowerCase() === 'true'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Preset {
|
||||||
|
title?: string
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
interface Settings {
|
interface Settings {
|
||||||
expandableImages: boolean
|
expandableImages: boolean
|
||||||
// should have been named "fade" read posts
|
// should have been named "fade" read posts
|
||||||
@@ -52,7 +57,7 @@ interface Settings {
|
|||||||
displayNames: boolean
|
displayNames: boolean
|
||||||
nsfwBlur: boolean
|
nsfwBlur: boolean
|
||||||
moderation: {
|
moderation: {
|
||||||
removalReasonPreset: string
|
presets: Preset[]
|
||||||
}
|
}
|
||||||
newVote: boolean
|
newVote: boolean
|
||||||
randomPlaceholders: boolean
|
randomPlaceholders: boolean
|
||||||
@@ -94,7 +99,12 @@ export const defaultSettings: Settings = {
|
|||||||
displayNames: toBool(env.PUBLIC_DISPLAY_NAMES) ?? true,
|
displayNames: toBool(env.PUBLIC_DISPLAY_NAMES) ?? true,
|
||||||
nsfwBlur: toBool(env.PUBLIC_NSFW_BLUR) ?? true,
|
nsfwBlur: toBool(env.PUBLIC_NSFW_BLUR) ?? true,
|
||||||
moderation: {
|
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,
|
newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false,
|
||||||
randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true,
|
randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true,
|
||||||
@@ -110,11 +120,27 @@ export const defaultSettings: Settings = {
|
|||||||
|
|
||||||
export const userSettings = writable(defaultSettings)
|
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') {
|
if (typeof window != 'undefined') {
|
||||||
let oldUserSettings = JSON.parse(
|
let oldUserSettings = JSON.parse(
|
||||||
localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
|
localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
oldUserSettings = migrate(oldUserSettings)
|
||||||
|
|
||||||
userSettings.set({ ...defaultSettings, ...oldUserSettings })
|
userSettings.set({ ...defaultSettings, ...oldUserSettings })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,25 @@
|
|||||||
import Setting from './Setting.svelte'
|
import Setting from './Setting.svelte'
|
||||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
import Sort from '$lib/components/lemmy/Sort.svelte'
|
import Sort from '$lib/components/lemmy/Sort.svelte'
|
||||||
import { toast } from 'mono-svelte'
|
import { Disclosure, Material, TextInput, toast } from 'mono-svelte'
|
||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import {
|
import {
|
||||||
ArrowPath,
|
ArrowPath,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronRight,
|
||||||
GlobeAmericas,
|
GlobeAmericas,
|
||||||
Icon,
|
Icon,
|
||||||
|
Plus,
|
||||||
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import { Button, Checkbox, Select } from 'mono-svelte'
|
import { Button, Checkbox, Select } from 'mono-svelte'
|
||||||
import ViewSelect from '$lib/components/lemmy/ViewSelect.svelte'
|
import ViewSelect from '$lib/components/lemmy/ViewSelect.svelte'
|
||||||
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
|
import { removeItem } from '$lib/util.js'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -243,9 +248,9 @@
|
|||||||
|
|
||||||
<SectionTitle class="mt-4" id="moderation">Moderation</SectionTitle>
|
<SectionTitle class="mt-4" id="moderation">Moderation</SectionTitle>
|
||||||
<Setting>
|
<Setting>
|
||||||
<span slot="title">Removal reply preset</span>
|
<span slot="title">Removal reply presets</span>
|
||||||
<span slot="description">
|
<span slot="description">
|
||||||
<p>The preset to use for "Reply reason" in a submission removal.</p>
|
<p>Presets to use for "Reply reason" in a submission removal.</p>
|
||||||
<ul class="leading-6">
|
<ul class="leading-6">
|
||||||
<li>Syntax:</li>
|
<li>Syntax:</li>
|
||||||
<li>
|
<li>
|
||||||
@@ -266,18 +271,64 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</span>
|
</span>
|
||||||
<MarkdownEditor
|
{#each $userSettings.moderation.presets as preset, index}
|
||||||
bind:value={$userSettings.moderation.removalReasonPreset}
|
<Material color="distinct" padding="md" class="py-3">
|
||||||
images={false}
|
<details>
|
||||||
previewButton
|
<summary
|
||||||
beforePreview={(input) =>
|
class="cursor-pointer inline-flex flex-row items-center w-full gap-1"
|
||||||
removalTemplate(input, {
|
>
|
||||||
postTitle: '<Example post>',
|
<Icon src={ChevronDown} mini size="16" slot="prefix" />
|
||||||
communityLink: '[!community@example.com]()',
|
{preset.title}
|
||||||
reason: '<Being a meanie>',
|
<Button
|
||||||
username: '@Bob',
|
size="square-md"
|
||||||
})}
|
class="ml-auto"
|
||||||
/>
|
on:click={() => {
|
||||||
|
$userSettings.moderation.presets.splice(index, 1)
|
||||||
|
$userSettings.moderation.presets =
|
||||||
|
$userSettings.moderation.presets
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
</summary>
|
||||||
|
<div class="flex flex-col gap-3 mt-2">
|
||||||
|
<TextInput
|
||||||
|
label="Title"
|
||||||
|
bind:value={preset.title}
|
||||||
|
placeholder="Reason 1"
|
||||||
|
/>
|
||||||
|
<MarkdownEditor
|
||||||
|
bind:value={preset.content}
|
||||||
|
label="Content"
|
||||||
|
images={false}
|
||||||
|
previewButton
|
||||||
|
beforePreview={(input) =>
|
||||||
|
removalTemplate(input, {
|
||||||
|
postTitle: '<Example post>',
|
||||||
|
communityLink: '[!community@example.com]()',
|
||||||
|
reason: '<Being a meanie>',
|
||||||
|
username: '@Bob',
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
</Material>
|
||||||
|
{/each}
|
||||||
|
<Button
|
||||||
|
on:click={() => {
|
||||||
|
$userSettings.moderation.presets = [
|
||||||
|
...$userSettings.moderation.presets,
|
||||||
|
{
|
||||||
|
title: `Preset ${$userSettings.moderation.presets.length + 1}`,
|
||||||
|
content:
|
||||||
|
'Your submission in *{{post}}* was removed for *{{reason}}*.',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon src={Plus} mini size="16" slot="prefix" />
|
||||||
|
Add Preset
|
||||||
|
</Button>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
|
||||||
<SectionTitle class="mt-4" id="other">Other</SectionTitle>
|
<SectionTitle class="mt-4" id="other">Other</SectionTitle>
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{#if $$slots.default}
|
{#if $$slots.default}
|
||||||
<div
|
<div
|
||||||
class="w-full px-5 py-3 bg-slate-50 dark:bg-zinc-950 border-t dark:border-zinc-800 mt-4"
|
class="w-full px-5 py-3 bg-slate-50 dark:bg-zinc-950 border-t dark:border-zinc-800 mt-4
|
||||||
|
flex flex-col gap-2"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user