From 47e20d9ca36a5f17b7b988c0e1c220f8cf3f5105 Mon Sep 17 00:00:00 2001 From: Xylight Date: Tue, 14 Nov 2023 17:41:34 -0800 Subject: [PATCH] fix: close #179 --- .../components/lemmy/comment/Comment.svelte | 88 +++++++++++-------- .../lemmy/comment/CommentForm.svelte | 7 +- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 6f8786a4..6eceebd5 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -30,46 +30,62 @@ let editing = false let newComment = node.comment_view.comment.content + + let editingLoad = false + + async function save() { + if (!$profile?.jwt || newComment.length <= 0) return + + editingLoad = true + + try { + await getClient().editComment({ + comment_id: node.comment_view.comment.id, + content: newComment, + }) + + node.comment_view.comment.content = newComment + + editing = false + + toast({ + content: 'Successfully edited comment.', + type: 'success', + }) + } catch (err) { + toast({ + // @ts-ignore i hate this + content: err, + type: 'error', + }) + } + + editingLoad = false + } {#if editing} - { - if (!$profile?.jwt || newComment.length <= 0) return - - try { - await getClient().editComment({ - comment_id: node.comment_view.comment.id, - content: newComment, - }) - - node.comment_view.comment.content = newComment - - editing = false - - toast({ - content: - 'Successfully edited comment. You may need to refresh to see changes.', - type: 'success', - }) - } catch (err) { - toast({ - // @ts-ignore i hate this - content: err, - type: 'error', - }) - } - }} - > + Edit comment - +
+ + +
{/if} diff --git a/src/lib/components/lemmy/comment/CommentForm.svelte b/src/lib/components/lemmy/comment/CommentForm.svelte index 081d1330..43a7a138 100644 --- a/src/lib/components/lemmy/comment/CommentForm.svelte +++ b/src/lib/components/lemmy/comment/CommentForm.svelte @@ -70,7 +70,12 @@ : placeholders.get('comment')} bind:value disabled={locked || loading} - on:confirm={submit} + on:confirm={() => { + if (actions) { + submit() + } + }} + on:confirm previewButton={previewAction} > {#if actions}