From 7f0a902d049dd3142e29ff060199459703684ef8 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Sun, 18 Dec 2022 01:31:33 +0300 Subject: [PATCH] add check --- src/components/Article/CommentsTree.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index f786fb00..1d548c4a 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -54,13 +54,12 @@ export const CommentsTree = (props: { shoutSlug: string }) => { } onMount(async () => await loadMore()) - function nestComments(commentList) { + const nestComments = (commentList) => { const commentMap = {} commentList.forEach((comment) => { commentMap[comment.id] = comment - if (comment.replyTo) { - if (!comment.replyTo) return - const parent = commentMap[comment.replyTo] + if (comment.replyTo !== null) { + const parent = commentMap[comment.replyTo] ?? [] ;(parent.children = parent.children || []).push(comment) } }) @@ -69,10 +68,6 @@ export const CommentsTree = (props: { shoutSlug: string }) => { }) } - createEffect(() => { - console.log('!!! reactions():', nestComments(reactions())) - }) - return ( <> }>