fix: view wont update on new comments, close #611

This commit is contained in:
James Xylight committed 2025-07-25 15:42:47 -07:00
1 parent 5b9777cc7a
commit 3b85d63004
2 files changed
+7 -7

No files matched your search

@@ -31,6 +31,7 @@
import { expoOut } from 'svelte/easing' import { expoOut } from 'svelte/easing'
import { fly } from 'svelte/transition' import { fly } from 'svelte/transition'
import CommentProvider from './CommentProvider.svelte' import CommentProvider from './CommentProvider.svelte'
import { ReactiveState } from '$lib/promise.svelte'
let { data } = $props() let { data } = $props()
@@ -261,16 +262,17 @@
</div> </div>
{/each} {/each}
</div> </div>
{:then comments} {:then passedComments}
{@const comments = new ReactiveState(passedComments)}
<CommentProvider <CommentProvider
{comments} comments={comments.value}
post={data.post.value} post={data.post.value}
focus={data.thread.value.focus} focus={data.thread.value.focus}
onupdate={reloadComments} onupdate={reloadComments}
bind:sort={data.commentSort.value} bind:sort={data.commentSort.value}
virtualize={!page.url.searchParams.get('noVirtualize')} virtualize={!page.url.searchParams.get('noVirtualize')}
/> />
{#if comments.comments.length == 0} {#if comments.value.comments.length == 0}
<Placeholder <Placeholder
icon={ChatBubbleLeftRight} icon={ChatBubbleLeftRight}
title={$t('routes.post.emptyComments.title')} title={$t('routes.post.emptyComments.title')}
@@ -38,7 +38,7 @@
let { let {
post, post,
comments: passedComments, comments,
sort = $bindable(), sort = $bindable(),
onupdate, onupdate,
focus, focus,
@@ -46,8 +46,6 @@
}: Props = $props() }: Props = $props()
let commenting = $state(false) let commenting = $state(false)
let comments = $derived(passedComments)
let tree = $state(buildCommentsTree(comments.comments)) let tree = $state(buildCommentsTree(comments.comments))
$effect(() => { $effect(() => {
tree = buildCommentsTree(comments.comments) tree = buildCommentsTree(comments.comments)
@@ -120,7 +118,7 @@
<CommentForm <CommentForm
postId={post.post_view.post.id} postId={post.post_view.post.id}
oncomment={comment => { oncomment={comment => {
comments.comments.push(comment.comment_view) comments.comments.unshift(comment.comment_view)
}} }}
onfocus={() => (commenting = true)} onfocus={() => (commenting = true)}
tools={commenting} tools={commenting}