From 810d6011a52f1c52a2eb2ba1e15c4ff80861ca4a Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Fri, 7 Jul 2023 15:18:12 -0700 Subject: [PATCH] misc: Fix comment loading --- src/lib/components/lemmy/comment/Comments.svelte | 14 ++++---------- src/routes/post/[instance]/[id]/+page.svelte | 6 ++++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/lib/components/lemmy/comment/Comments.svelte b/src/lib/components/lemmy/comment/Comments.svelte index f8c33412..9aee2551 100644 --- a/src/lib/components/lemmy/comment/Comments.svelte +++ b/src/lib/components/lemmy/comment/Comments.svelte @@ -38,19 +38,13 @@ const newComments = await getClient().getComments({ auth: $authData?.token, max_depth: 3, + limit: 10, parent_id: parent.comment_view.comment.id, }) - parent.children = buildCommentsTree( - newComments.comments.filter( - (comment) => comment.comment.id != parent.comment_view.comment.id - ), - true - ).map((node) => ({ - children: node.children, - comment_view: node.comment_view, - depth: node.depth + parent.depth, - })) + parent.children = buildCommentsTree(newComments.comments, true).find( + (c) => c.comment_view.comment.id == parent.comment_view.comment.id + )!.children loadingChildren = false } diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte index a1b27961..b39fd724 100644 --- a/src/routes/post/[instance]/[id]/+page.svelte +++ b/src/routes/post/[instance]/[id]/+page.svelte @@ -162,10 +162,12 @@ post_id: data.post.post_view.post.id, }) - if (loadedComments.comments.length > 0) { + if (comments.comments == loadedComments.comments) { comments.comments = [ ...comments.comments, - ...loadedComments.comments, + ...loadedComments.comments.filter( + (comment) => !comments.comments.includes(comment) + ), ] } else { moreComments = false