misc: Fix comment loading

This commit is contained in:
Xyphyn committed 2023-07-07 15:18:12 -07:00
1 parent 5f7741768b
commit 810d6011a5
2 files changed
+8 -12

No files matched your search

@@ -38,19 +38,13 @@
const newComments = await getClient().getComments({ const newComments = await getClient().getComments({
auth: $authData?.token, auth: $authData?.token,
max_depth: 3, max_depth: 3,
limit: 10,
parent_id: parent.comment_view.comment.id, parent_id: parent.comment_view.comment.id,
}) })
parent.children = buildCommentsTree( parent.children = buildCommentsTree(newComments.comments, true).find(
newComments.comments.filter( (c) => c.comment_view.comment.id == parent.comment_view.comment.id
(comment) => comment.comment.id != parent.comment_view.comment.id )!.children
),
true
).map((node) => ({
children: node.children,
comment_view: node.comment_view,
depth: node.depth + parent.depth,
}))
loadingChildren = false loadingChildren = false
} }
+4 -2
View File
@@ -162,10 +162,12 @@
post_id: data.post.post_view.post.id, post_id: data.post.post_view.post.id,
}) })
if (loadedComments.comments.length > 0) { if (comments.comments == loadedComments.comments) {
comments.comments = [ comments.comments = [
...comments.comments, ...comments.comments,
...loadedComments.comments, ...loadedComments.comments.filter(
(comment) => !comments.comments.includes(comment)
),
] ]
} else { } else {
moreComments = false moreComments = false