fix: close #179
This commit is contained in:
1 parent
a6249dba60
commit
47e20d9ca3
2 files changed
+58
-37
No files matched your search
@@ -30,46 +30,62 @@
|
|||||||
|
|
||||||
let editing = false
|
let editing = false
|
||||||
let newComment = node.comment_view.comment.content
|
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
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if editing}
|
{#if editing}
|
||||||
<Modal
|
<Modal bind:open={editing}>
|
||||||
bind:open={editing}
|
|
||||||
action="Save"
|
|
||||||
on:action={async () => {
|
|
||||||
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',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span slot="title">Edit comment</span>
|
<span slot="title">Edit comment</span>
|
||||||
<CommentForm
|
<form on:submit|preventDefault={save} class="contents">
|
||||||
postId={node.comment_view.comment.id}
|
<CommentForm
|
||||||
bind:value={newComment}
|
postId={node.comment_view.comment.id}
|
||||||
actions={false}
|
bind:value={newComment}
|
||||||
preview={true}
|
actions={false}
|
||||||
/>
|
preview={true}
|
||||||
|
on:confirm={save}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
submit
|
||||||
|
color="primary"
|
||||||
|
size="lg"
|
||||||
|
loading={editingLoad}
|
||||||
|
disabled={editingLoad}
|
||||||
|
class="w-full"
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,12 @@
|
|||||||
: placeholders.get('comment')}
|
: placeholders.get('comment')}
|
||||||
bind:value
|
bind:value
|
||||||
disabled={locked || loading}
|
disabled={locked || loading}
|
||||||
on:confirm={submit}
|
on:confirm={() => {
|
||||||
|
if (actions) {
|
||||||
|
submit()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
on:confirm
|
||||||
previewButton={previewAction}
|
previewButton={previewAction}
|
||||||
>
|
>
|
||||||
{#if actions}
|
{#if actions}
|
||||||
|
|||||||
Reference in new issue
Block a user