feat: switch to universal delete function

This commit is contained in:
Xyphyn committed 2023-08-19 13:48:15 -07:00
1 parent 5de92f7ae3
commit 6a4d4077b4
3 files changed
+47 -21

No files matched your search

@@ -32,7 +32,7 @@
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import { profile } from '$lib/auth.js'
import { save } from '$lib/lemmy/contentview.js'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
export let comment: CommentView
export let replying: boolean = false
@@ -101,27 +101,16 @@
<MenuButton
color="dangerSecondary"
on:click={async () => {
if (!$profile?.jwt) return
try {
await getClient().deleteComment({
auth: $profile.jwt,
comment_id: comment.comment.id,
deleted: true,
})
toast({
content: 'The comment was deleted.',
type: 'success',
})
} catch (error) {
toast({
content: 'Failed to delete comment',
type: 'error',
})
}
if ($profile?.jwt)
comment.comment.deleted = await deleteItem(
comment,
!comment.comment.deleted,
$profile.jwt
)
}}
>
<Icon src={Trash} mini size="16" />
<span>Delete</span>
<span>{comment.comment.deleted ? 'Restore' : 'Delete'}</span>
</MenuButton>
{/if}
{#if $profile.jwt && $profile.user?.local_user_view.person.id != comment.creator.id}
@@ -31,7 +31,7 @@
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.js'
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import { save } from '$lib/lemmy/contentview.js'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
export let post: PostView
@@ -166,7 +166,17 @@
{post.saved ? 'Unsave' : 'Save'}
</MenuButton>
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
<MenuButton on:click={deletePost} color="dangerSecondary">
<MenuButton
on:click={async () => {
if ($profile?.jwt)
post.post.deleted = await deleteItem(
post,
!post.post.deleted,
$profile.jwt
)
}}
color="dangerSecondary"
>
<Icon src={Trash} width={16} mini />
{post.post.deleted ? 'Restore' : 'Delete'}
</MenuButton>