fix: comments are now reactive

This commit is contained in:
James Xylight committed 2025-02-03 20:09:30 -08:00
1 parent 9025f5db18
commit fc79775ce3
4 files changed
+17 -19

No files matched your search

@@ -16,11 +16,13 @@
let { nodes, post, scrollTo }: Props = $props() let { nodes, post, scrollTo }: Props = $props()
let nodesState = $state(nodes)
let virtualListEl = $state<HTMLElement>() let virtualListEl = $state<HTMLElement>()
let virtualizer = $derived( let virtualizer = $derived(
createWindowVirtualizer({ createWindowVirtualizer({
count: nodes.length, count: nodesState.length,
estimateSize: () => 30, estimateSize: () => 30,
scrollMargin: virtualListEl?.offsetTop, scrollMargin: virtualListEl?.offsetTop,
initialRect: { initialRect: {
@@ -71,7 +73,7 @@
data-index={row.index} data-index={row.index}
class="-mx-4 sm:-mx-6 px-4 sm:px-6" class="-mx-4 sm:-mx-6 px-4 sm:px-6"
> >
<Comments isParent={true} nodes={[nodes[row.index]]} {post} /> <Comments isParent={true} nodes={[nodesState[row.index]]} {post} />
</div> </div>
{/each} {/each}
</div> </div>
@@ -48,7 +48,7 @@
</script> </script>
<div <div
class="h-full flex items-center overflow-hidden {buttonColor.ghost} rounded-full hover:bg-transparent" class="h-full flex items-center overflow-hidden {buttonColor.ghost} rounded-full hover:bg-transparent font-medium"
> >
<button <button
onclick={() => castVote(vote == 1 ? 0 : 1)} onclick={() => castVote(vote == 1 ? 0 : 1)}
@@ -43,7 +43,7 @@
*/ */
editingPost?: Post | undefined editingPost?: Post | undefined
passedCommunity?: Community | undefined passedCommunity?: Community | undefined
data?: { passedData?: {
community: Community | null community: Community | null
title: string title: string
body: string body: string
@@ -63,7 +63,7 @@
edit = false, edit = false,
editingPost = undefined, editingPost = undefined,
passedCommunity = undefined, passedCommunity = undefined,
data = $bindable({ passedData = {
community: null, community: null,
title: '', title: '',
body: '', body: '',
@@ -74,11 +74,13 @@
loading: false, loading: false,
alt_text: undefined, alt_text: undefined,
language_id: undefined, language_id: undefined,
}), },
formtitle, formtitle,
onsubmit, onsubmit,
}: Props = $props() }: Props = $props()
let data = $state(passedData)
// weird select menu language handling // weird select menu language handling
// @ts-ignore // @ts-ignore
$effect(() => { $effect(() => {
@@ -341,11 +343,9 @@
/> />
<div class="flex items-center gap-2 actions"> <div class="flex items-center gap-2 actions">
<div <div
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center" class="border border-slate-100 dark:border-zinc-800 dark:text-zinc-400 text-slate-600 rounded-xl h-6 w-6 grid place-items-center"
> >
{#snippet prefix()} <Icon src={Plus} size="16" micro />
<Icon src={Plus} size="16" micro />
{/snippet}
</div> </div>
{#if data.url} {#if data.url}
<Button <Button
@@ -492,8 +492,9 @@
</Button> </Button>
</div> </div>
{/if} {/if}
{#if comments} <CommentListVirtualizer
{@const tree = buildCommentsTree( post={data.post.post_view.post}
nodes={buildCommentsTree(
comments.comments, comments.comments,
undefined, undefined,
(c) => (c) =>
@@ -502,13 +503,8 @@
(settings.hidePosts.removed && c.comment.removed) (settings.hidePosts.removed && c.comment.removed)
), ),
)} )}
scrollTo={data.thread.focus}
<CommentListVirtualizer />
post={data.post.post_view.post}
nodes={createCommentsState(tree)}
scrollTo={data.thread.focus}
/>
{/if}
{#if comments.comments.length == 0} {#if comments.comments.length == 0}
<Placeholder <Placeholder
icon={ChatBubbleLeftRight} icon={ChatBubbleLeftRight}