Skip to content

Commit 1cd1906

Browse files
fix sorting replies (#3783)
* fix sorting replies * fix typing
1 parent ce0333e commit 1cd1906

File tree

1 file changed

+25
-3
lines changed
  • packages/app/src/app/overmind/namespaces/comments

1 file changed

+25
-3
lines changed

packages/app/src/app/overmind/namespaces/comments/state.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,33 @@ export const state: State = {
8484
return null;
8585
}
8686

87+
function sortByInsertedAt(
88+
commentA: CommentFragment | null,
89+
commentB: CommentFragment | null
90+
) {
91+
if (!commentA || !commentB) {
92+
return 0;
93+
}
94+
95+
const aDate = new Date(commentA.insertedAt);
96+
const bDate = new Date(commentB.insertedAt);
97+
98+
if (aDate > bDate) {
99+
return 1;
100+
}
101+
102+
if (bDate < aDate) {
103+
return -1;
104+
}
105+
106+
return 0;
107+
}
108+
87109
return {
88110
...comments[currentSandbox.id][currentCommentId],
89-
comments: comments[currentSandbox.id][currentCommentId].comments.map(
90-
commentId => comments[currentSandbox.id][commentId.id] || null
91-
),
111+
comments: comments[currentSandbox.id][currentCommentId].comments
112+
.map(commentId => comments[currentSandbox.id][commentId.id] || null)
113+
.sort(sortByInsertedAt),
92114
};
93115
},
94116
selectedCommentsFilter: CommentsFilterOption.OPEN,

0 commit comments

Comments
 (0)