fix: use inline reply editor for comments (#590)

This commit is contained in:
Xylight authored and GitHub committed 2025-06-20 11:19:19 -07:00
1 parent cbf6622d65
commit 56ac2631b5
1 file changed
+45 -69
+45 -69
View File
@@ -8,13 +8,14 @@
import { t } from '$lib/i18n/translations' import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js' import { getClient } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error' import { errorMessage } from '$lib/lemmy/error'
import { Button, Material, Modal, toast } from 'mono-svelte' import { Button, Modal, toast } from 'mono-svelte'
import { Bookmark, Icon, Microphone, Pencil, Trash } from 'svelte-hero-icons' import { Bookmark, Icon, Microphone, Pencil, Trash } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import type { ClassValue } from 'svelte/elements' import type { ClassValue } from 'svelte/elements'
import { slide } from 'svelte/transition'
import ShieldIcon from '../moderation/ShieldIcon.svelte' import ShieldIcon from '../moderation/ShieldIcon.svelte'
import CommentForm from './CommentForm.svelte' import CommentForm from './CommentForm.svelte'
import type { CommentNodeI } from './comments.svelte' import type { CommentNodeI } from './comments.svelte'
import CommentItem from './CommentItem.svelte'
interface Props { interface Props {
node: CommentNodeI node: CommentNodeI
@@ -85,38 +86,11 @@
}, 500) }, 500)
</script> </script>
{#if editing || replying} {#if editing}
<Modal <Modal bind:open={editing}>
bind:open={
() => replying || editing,
v => {
replying = v
editing = v
}
}
>
{#snippet customTitle()} {#snippet customTitle()}
<div>{replying ? $t('comment.reply') : $t('form.edit')}</div> <div>{$t('form.edit')}</div>
{/snippet} {/snippet}
{#if replying}
<Material
rounding="2xl"
color="uniform"
class="max-h-48 overflow-hidden relative"
>
<UserLink user={node.comment_view.creator} />
<CommentItem
meta={false}
comment={node.comment_view}
class="pt-0 text-slate-700 dark:text-zinc-300"
actions={false}
/>
<div
class="bg-gradient-to-b -mx-4 from-white/0 to-white dark:from-zinc-900/0 dark:to-zinc-900 absolute bottom-0 w-full h-24"
></div>
</Material>
{/if}
<form <form
onsubmit={e => { onsubmit={e => {
e.preventDefault() e.preventDefault()
@@ -124,43 +98,22 @@
}} }}
class="contents" class="contents"
> >
{#if replying} <CommentForm
<CommentForm bind:value={newComment}
label={$t('comment.reply')} postId={node.comment_view.comment.id}
{postId} actions={false}
parentId={node.comment_view.comment.id} preview={true}
oncomment={e => { />
node.children = [ <Button
{ submit
children: [], color="primary"
comment_view: e.comment_view, size="lg"
depth: node.depth + 1, loading={editingLoad}
expanded: true, disabled={editingLoad}
}, class="w-full"
...node.children, >
] {$t('form.submit')}
replying = false </Button>
}}
oncancel={() => (replying = false)}
/>
{:else if editing}
<CommentForm
bind:value={newComment}
postId={node.comment_view.comment.id}
actions={false}
preview={true}
/>
<Button
submit
color="primary"
size="lg"
loading={editingLoad}
disabled={editingLoad}
class="w-full"
>
{$t('form.submit')}
</Button>
{/if}
</form> </form>
</Modal> </Modal>
{/if} {/if}
@@ -250,6 +203,29 @@
/> />
{/if} {/if}
</div> </div>
{#if replying}
<div transition:slide={{ duration: 600, easing: expoOut }}>
<CommentForm
label={$t('comment.reply')}
{postId}
parentId={node.comment_view.comment.id}
oncomment={e => {
node.children = [
{
children: [],
comment_view: e.comment_view,
depth: node.depth + 1,
expanded: true,
},
...node.children,
]
replying = false
}}
oncancel={() => (replying = false)}
/>
</div>
{/if}
<div class="bg-transparent dark:bg-transparent"> <div class="bg-transparent dark:bg-transparent">
{@render children?.()} {@render children?.()}
</div> </div>