diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-02-14 13:57:06 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-02-14 14:15:54 +0100 |
| commit | 637350e4d152de1346857d645bda8443900ec6f4 (patch) | |
| tree | 23b43c7ce7e25935efe5b1dd156ad186334ee956 /src/utils/helpers/format.ts | |
| parent | 9c150f28e4a23dfb4965fc3a4cdee16933a3def5 (diff) | |
fix: update comments list when a new comment is send
The comments list was static before. If an user posted a comment, even
after it was approved, the comments list was keeping the old state.
Diffstat (limited to 'src/utils/helpers/format.ts')
| -rw-r--r-- | src/utils/helpers/format.ts | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 817daaf..9c6f266 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -189,14 +189,16 @@ export const buildCommentsTree = (comments: Comment[]) => { const commentsTree: Comment[] = []; comments.forEach( - (comment) => (hashTable[comment.id] = { ...comment, replies: [] }) + (comment) => (hashTable[comment.commentId] = { ...comment, replies: [] }) ); comments.forEach((comment) => { - if (!comment.parentId) { - commentsTree.push(hashTable[comment.id]); + if (!comment.parentDatabaseId) { + commentsTree.push(hashTable[comment.commentId]); } else { - hashTable[comment.parentId].replies.push(hashTable[comment.id]); + hashTable[comment.parentDatabaseId].replies.push( + hashTable[comment.commentId] + ); } }); @@ -226,7 +228,6 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { acfPosts, author, commentCount, - comments, contentParts, databaseId, date, @@ -243,8 +244,6 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { update: modified, }; - const formattedComments = getFormattedComments(comments.nodes); - const commentsTree = buildCommentsTree(formattedComments); const topics = acfPosts.postsInTopic ? getFormattedTopicsPreview(acfPosts.postsInTopic) : []; @@ -252,7 +251,6 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { const formattedPost: Article = { author: author.node, commentCount, - comments: commentsTree, content: contentParts.afterMore, databaseId, dates, |
