mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(use-replies): sort by timestamp and move pinned replies to the top
This commit is contained in:
@@ -28,14 +28,18 @@ const useRepliesAndAccountReplies = (comment: Comment) => {
|
|||||||
}, [flattenedReplies, accountComments]);
|
}, [flattenedReplies, accountComments]);
|
||||||
|
|
||||||
const repliesAndNotYetPublishedReplies = useMemo(() => {
|
const repliesAndNotYetPublishedReplies = useMemo(() => {
|
||||||
const repliesSortedByVotes = [
|
const repliesSortedByPinnedAndTimestamp = [...accountRepliesNotYetPublished.reverse(), ...(flattenedReplies || [])];
|
||||||
// put the author's unpublished replies at the top, latest first (reverse)
|
|
||||||
...accountRepliesNotYetPublished.reverse(),
|
return repliesSortedByPinnedAndTimestamp.sort((a: Comment, b: Comment) => {
|
||||||
// put the published replies after,
|
// Sort by pinned status first, with pinned comments at the top
|
||||||
...(flattenedReplies || []),
|
if (a.pinned && !b.pinned) {
|
||||||
];
|
return -1;
|
||||||
// sort by timestamp
|
} else if (!a.pinned && b.pinned) {
|
||||||
return repliesSortedByVotes.sort((a: Comment, b: Comment) => a.timestamp - b.timestamp);
|
return 1;
|
||||||
|
}
|
||||||
|
// If both are pinned or both are not pinned, sort by timestamp
|
||||||
|
return a.timestamp - b.timestamp;
|
||||||
|
});
|
||||||
}, [flattenedReplies, accountRepliesNotYetPublished]);
|
}, [flattenedReplies, accountRepliesNotYetPublished]);
|
||||||
|
|
||||||
return repliesAndNotYetPublishedReplies;
|
return repliesAndNotYetPublishedReplies;
|
||||||
|
|||||||
Reference in New Issue
Block a user