feat: Add post and comment editing (#12)

* feat: Add editing

* feat: Add comment badges

* fix: make loading more consistent

* misc: remove prop drilling

* feat: Add post editing

* misc: update version

* feat: Add comment deletion
This commit is contained in:
Xylight authored and GitHub committed 2023-07-25 11:12:15 -07:00
1 parent 0327ae4aed
commit 7b1ad247f9
16 files changed
+417 -192

No files matched your search

@@ -9,12 +9,16 @@
ChatBubbleOvalLeft,
EllipsisHorizontal,
Icon,
PencilSquare,
Trash,
} from 'svelte-hero-icons'
import { authData, getClient } from '$lib/lemmy.js'
import { authData, getClient, user } from '$lib/lemmy.js'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import Menu from '$lib/components/ui/menu/Menu.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import Button from '$lib/components/input/Button.svelte'
import { createEventDispatcher } from 'svelte'
import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js'
export let comment: CommentView
export let replying: boolean = false
@@ -41,6 +45,8 @@
})
}
}
const dispatcher = createEventDispatcher<{ edit: CommentView }>()
</script>
<div class="flex flex-row gap-2 items-center mt-1 h-[26px] relative">
@@ -53,34 +59,59 @@
<Icon src={ChatBubbleOvalLeft} width={16} height={16} mini />
<span class="text-xs">Reply</span>
</Button>
<div class="h-full relative">
<Menu
let:toggleOpen
class="h-[26px] top-0"
absolute
alignment="bottom-center"
<Menu
let:toggleOpen
class="h-[26px] top-0 leading-3"
alignment="bottom-center"
>
<Button
slot="button"
color="elevatedLow"
on:click={toggleOpen}
size="sm"
class="!p-1"
>
<Button
slot="button"
color="elevatedLow"
on:click={toggleOpen}
size="sm"
class="!p-1"
>
<Icon
src={EllipsisHorizontal}
width={16}
height={16}
mini
slot="icon"
/>
</Button>
{#if $authData?.token}
<MenuButton on:click={save}>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
<Icon src={EllipsisHorizontal} width={16} height={16} mini slot="icon" />
</Button>
<span class="text-xs opacity-80 py-1 my-1 px-4">Comment actions</span>
{#if $authData?.token}
{#if comment.creator.id == $user?.person.id}
<MenuButton on:click={() => dispatcher('edit', comment)}>
<Icon src={PencilSquare} mini size="16" />
<span>Edit</span>
</MenuButton>
{/if}
</Menu>
</div>
<MenuButton on:click={save}>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
</MenuButton>
{#if $user && $authData && isCommentMutable(comment, $user)}
<MenuButton
color={Color.dangerSecondary}
on:click={async () => {
if (!$authData) return
try {
await getClient().deleteComment({
auth: $authData.token,
comment_id: comment.comment.id,
deleted: true,
})
toast({
content: 'The comment was deleted.',
type: ToastType.success,
})
} catch (error) {
toast({
content: 'Failed to delete comment',
type: ToastType.error,
})
}
}}
>
<Icon src={Trash} mini size="16" />
<span>Delete</span>
</MenuButton>
{/if}
{/if}
</Menu>
</div>