feat: add reporting

This commit is contained in:
Xyphyn committed 2023-07-26 19:13:26 -07:00
1 parent ff2d424a99
commit 6fcef02809
14 files changed
+206 -33

No files matched your search

@@ -25,6 +25,7 @@
export let node: CommentNodeI
export let postId: number
export let op: boolean = false
export let actions: boolean = true
export let open = true
export let replying = false
@@ -71,7 +72,7 @@
{/if}
<li
class="py-2 {node.depth == 0
class="py-2 pb-3 {node.depth == 0
? 'border-b border-slate-200 dark:border-zinc-800'
: ''}"
id="#{node.comment_view.comment.id.toString()}"
@@ -140,13 +141,15 @@
<div class="max-w-full mt-0.5 break-words text-sm leading-[22px]">
<Markdown source={node.comment_view.comment.content} />
</div>
<div class="flex flex-row gap-2 items-center h-[26px]">
<CommentActions
comment={node.comment_view}
bind:replying
on:edit={() => (editing = true)}
/>
</div>
{#if actions}
<div class="flex flex-row gap-2 items-center h-[26px]">
<CommentActions
comment={node.comment_view}
bind:replying
on:edit={() => (editing = true)}
/>
</div>
{/if}
</div>
{#if replying}
<div class="max-w-sm my-2">
@@ -10,6 +10,7 @@
BookmarkSlash,
ChatBubbleOvalLeft,
EllipsisHorizontal,
Flag,
Icon,
PencilSquare,
Trash,
@@ -21,6 +22,7 @@
import Button from '$lib/components/input/Button.svelte'
import { createEventDispatcher } from 'svelte'
import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js'
import { report } from '$lib/components/lemmy/moderation/moderation.js'
export let comment: CommentView
export let replying: boolean = false
@@ -114,6 +116,15 @@
<span>Delete</span>
</MenuButton>
{/if}
{#if $authData && $user?.person.id != comment.creator.id}
<MenuButton
on:click={() => report(comment)}
color={Color.dangerSecondary}
>
<Icon src={Flag} mini size="16" />
<span>Report</span>
</MenuButton>
{/if}
{/if}
</Menu>
</div>
@@ -0,0 +1,6 @@
<script lang="ts">
import { modals } from '$lib/components/lemmy/moderation/moderation.js'
import ReportModal from './ReportModal.svelte'
</script>
<ReportModal bind:open={$modals.reporting.open} item={$modals.reporting.item} />
@@ -0,0 +1,94 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
import TextArea from '$lib/components/input/TextArea.svelte'
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import Post from '$lib/components/lemmy/post/Post.svelte'
import Modal from '$lib/components/ui/modal/Modal.svelte'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import { authData, getClient } from '$lib/lemmy.js'
import type { CommentView, PostView } from 'lemmy-js-client'
export let open: boolean
export let item: PostView | CommentView | undefined = undefined
const isComment = (item: PostView | CommentView): item is CommentView =>
'comment' in item
const isPost = (item: PostView | CommentView): item is PostView =>
!isComment(item)
let loading = false
let reason = ''
async function report() {
if (!item || !$authData) return
loading = true
try {
if (isComment(item)) {
await getClient().createCommentReport({
auth: $authData.token,
comment_id: item.comment.id,
reason: reason,
})
} else if (isPost(item)) {
await getClient().createPostReport({
auth: $authData.token,
post_id: item.post.id,
reason: reason,
})
}
toast({
content: 'That submission has been reported.',
type: ToastType.success,
})
} catch (err) {
toast({ content: err as any, type: ToastType.error })
}
loading = false
}
const resetText = () => (reason = '')
$: {
if (item) {
resetText()
}
}
</script>
<Modal bind:open>
<h1 class="font-bold text-2xl" slot="title">Report</h1>
<form class="flex flex-col gap-4" on:submit|preventDefault={report}>
{#if item}
<span>Reporting this submission</span>
<div class="pointer-events-none list-none">
{#if isComment(item)}
<Comment
actions={false}
node={{
children: [],
comment_view: item,
depth: 1,
loading: false,
}}
postId={item.post.id}
/>
{:else if isPost(item)}
<Post actions={false} post={item} />
{/if}
</div>
{/if}
<TextArea
required
rows={3}
label="Reason"
placeholder="he's being a meanie :("
bind:value={reason}
/>
<Button submit {loading} disabled={loading} color="primary" size="lg">
Submit
</Button>
</form>
</Modal>
@@ -0,0 +1,26 @@
import type { CommentView, PostView } from 'lemmy-js-client'
import { writable } from 'svelte/store'
interface Modals {
reporting: {
open: boolean
item: PostView | CommentView | undefined
}
}
export let modals = writable<Modals>({
reporting: {
open: true,
item: undefined,
},
})
export function report(item: PostView | CommentView) {
modals.update((m) => ({
...m,
reporting: {
open: true,
item: item,
},
}))
}
+16 -12
View File
@@ -12,6 +12,8 @@
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
export let post: PostView
export let actions: boolean = true
</script>
<Card class="bg-white flex flex-col w-full p-5 gap-2.5">
@@ -111,16 +113,18 @@
</p>
{/if}
{/if}
<PostActions
{post}
on:edit={(e) => {
post.post.name = e.detail.post.name
post.post.body = e.detail.post.body
post.post.url = e.detail.post.url
toast({
content: 'The post was edited successfully.',
type: ToastType.success,
})
}}
/>
{#if actions}
<PostActions
{post}
on:edit={(e) => {
post.post.name = e.detail.post.name
post.post.body = e.detail.post.body
post.post.url = e.detail.post.url
toast({
content: 'The post was edited successfully.',
type: ToastType.success,
})
}}
/>
{/if}
</Card>
@@ -9,6 +9,7 @@
BookmarkSlash,
ChatBubbleOvalLeft,
EllipsisHorizontal,
Flag,
Icon,
Newspaper,
PencilSquare,
@@ -27,6 +28,7 @@
import { createEventDispatcher } from 'svelte'
import Modal from '$lib/components/ui/modal/Modal.svelte'
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
import { report } from '$lib/components/lemmy/moderation/moderation.js'
export let post: PostView
@@ -142,12 +144,18 @@
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
{post.saved ? 'Unsave' : 'Save'}
</MenuButton>
{/if}
{#if $user && isMutable(post, $user)}
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
<Icon src={Trash} width={16} mini />
Delete
</MenuButton>
{#if $user && isMutable(post, $user)}
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
<Icon src={Trash} width={16} mini />
Delete
</MenuButton>
{/if}
{#if $user?.person.id != post.creator.id}
<MenuButton on:click={() => report(post)} color={Color.dangerSecondary}>
<Icon src={Flag} width={16} mini />
Report
</MenuButton>
{/if}
{/if}
</Menu>
</div>