fix(replies): order approved queue replies

This commit is contained in:
Tommaso Casaburi
2026-04-27 15:12:52 +07:00
parent 5dc5408a15
commit 463509e105
4 changed files with 168 additions and 14 deletions
+8 -3
View File
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import { Comment, useAccountComments } from '@bitsocial/bitsocial-react-hooks';
import { sortRepliesForDisplay } from '../lib/utils/replies-preview-utils';
// Keep the hook on its indexed fast path when there are no reply indices to resolve.
const EMPTY_ACCOUNT_COMMENT_LOOKUP = { commentIndices: [-1] };
@@ -13,10 +14,14 @@ const useFreshReplies = (replies: Comment[] = []) => {
const { accountComments } = useAccountComments(accountCommentLookupOptions);
return useMemo(() => {
if (!replies.length || !accountComments?.length) {
if (!replies.length) {
return replies;
}
if (!accountComments?.length) {
return sortRepliesForDisplay(replies);
}
const accountCommentsByIndex = new Map<number, Comment>();
for (const accountComment of accountComments) {
if (typeof accountComment?.index === 'number') {
@@ -40,7 +45,7 @@ const useFreshReplies = (replies: Comment[] = []) => {
});
if (!hasFreshReplies) {
return replies;
return sortRepliesForDisplay(replies);
}
const seenReplyIndices = new Set<number>();
@@ -59,7 +64,7 @@ const useFreshReplies = (replies: Comment[] = []) => {
return true;
});
return hasDuplicateReplyIndices ? dedupedReplies : nextReplies;
return sortRepliesForDisplay(hasDuplicateReplyIndices ? dedupedReplies : nextReplies);
}, [accountComments, replies]);
};