Skip to content

Commit

Permalink
fix: remove duplicate comments (#3427)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts authored Apr 6, 2024
1 parent 6a722da commit 4b95f4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export const transformToTree = (comments: CommentWithRepliesParent[]) => {

if (comment.parentCommentId) {
const parentComment = commentsById[comment.parentCommentId]

if (!parentComment) {
continue
}

if (!parentComment.replies) {
parentComment.replies = []
}
Expand Down
7 changes: 7 additions & 0 deletions src/stores/Research/research.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ export class ResearchStore extends ModuleStore {
enrichedResearchUpdated.comments = discussion
? (update.comments || []).concat(discussion.comments)
: []

// Remove duplicate comments based on _id proprety
enrichedResearchUpdated.comments = [
...new Map(
enrichedResearchUpdated.comments.map((item) => [item._id, item]),
).values(),
]
return enrichedResearchUpdated
}

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"declaration": true,
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": false
"useUnknownInCatchVariables": false,
"downlevelIteration": true
},
"include": ["src/**/*", "types"],
"exclude": [
Expand Down

0 comments on commit 4b95f4d

Please sign in to comment.