feat: comment a reply when removing a submission
This commit is contained in:
1 parent
59e60fe4cf
commit
2eaee8628d
2 files changed
+47
-2
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.5.8",
|
"version": "0.5.9",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -9,11 +9,14 @@
|
|||||||
import { isComment, isPost } from '$lib/lemmy/item.js'
|
import { isComment, isPost } from '$lib/lemmy/item.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||||
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
|
|
||||||
export let open: boolean
|
export let open: boolean
|
||||||
export let item: PostView | CommentView | undefined = undefined
|
export let item: PostView | CommentView | undefined = undefined
|
||||||
|
|
||||||
let reason = ''
|
let reason = ''
|
||||||
|
let commentReason: boolean = false
|
||||||
let loading = false
|
let loading = false
|
||||||
|
|
||||||
$: removed = item
|
$: removed = item
|
||||||
@@ -22,6 +25,8 @@
|
|||||||
: item.post.removed
|
: item.post.removed
|
||||||
: false
|
: false
|
||||||
|
|
||||||
|
$: replyReason = `Your submission was removed for:\n${reason}`
|
||||||
|
|
||||||
async function remove() {
|
async function remove() {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
if (!$profile?.jwt) throw new Error('Unauthenticated')
|
if (!$profile?.jwt) throw new Error('Unauthenticated')
|
||||||
@@ -29,6 +34,29 @@
|
|||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (commentReason) {
|
||||||
|
if (replyReason == '') {
|
||||||
|
toast({
|
||||||
|
content: 'Your reply cannot be empty if "Reply reason" is enabled.',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await getClient()
|
||||||
|
.createComment({
|
||||||
|
auth: $profile.jwt,
|
||||||
|
content: replyReason,
|
||||||
|
post_id: item.post.id,
|
||||||
|
parent_id: isComment(item) ? item.comment.id : undefined,
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
toast({
|
||||||
|
content: 'Failed to post reply. Removing anyway...',
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (isComment(item)) {
|
if (isComment(item)) {
|
||||||
await getClient().removeComment({
|
await getClient().removeComment({
|
||||||
auth: $profile.jwt,
|
auth: $profile.jwt,
|
||||||
@@ -66,7 +94,11 @@
|
|||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetText = () => (reason = '')
|
const resetText = () => {
|
||||||
|
reason = ''
|
||||||
|
replyReason = ''
|
||||||
|
commentReason = false
|
||||||
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (item) {
|
if (item) {
|
||||||
@@ -103,6 +135,19 @@
|
|||||||
bind:value={reason}
|
bind:value={reason}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{#if !removed}
|
||||||
|
<Checkbox bind:checked={commentReason}>Reply with reason</Checkbox>
|
||||||
|
|
||||||
|
{#if commentReason}
|
||||||
|
<MarkdownEditor
|
||||||
|
bind:value={replyReason}
|
||||||
|
placeholder={replyReason}
|
||||||
|
rows={3}
|
||||||
|
label="Reply"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
<Button color="primary" size="lg" {loading} disabled={loading} submit>
|
<Button color="primary" size="lg" {loading} disabled={loading} submit>
|
||||||
{removed ? 'Restore' : 'Remove'}
|
{removed ? 'Restore' : 'Remove'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in new issue
Block a user