fix(board-replies): include pending and mod-queue account comments in 5-reply preview

This commit is contained in:
plebeius
2026-02-26 15:19:25 +08:00
parent 216073aee3
commit 9253bad7a5
2 changed files with 25 additions and 5 deletions
+3 -1
View File
@@ -40,6 +40,7 @@ import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-util
import useQuotedByMap from '../../hooks/use-quoted-by-map';
import useProgressiveRender from '../../hooks/use-progressive-render';
import { BOARD_REPLIES_PREVIEW_FETCH_SIZE, BOARD_REPLIES_PREVIEW_VISIBLE_COUNT, REPLIES_PER_PAGE } from '../../lib/constants';
import { getPreviewDisplayReplies } from '../../lib/utils/replies-preview-utils';
const { addChallenge } = useChallengesStore.getState();
@@ -590,6 +591,7 @@ const PostMobile = ({
// Filter out deleted replies with no children for both virtuoso and non-virtuoso rendering
const filteredReplies = repliesForRender.filter((reply) => !(reply.deleted && (reply.replyCount === 0 || !reply.replyCount)));
const previewDisplayReplies = getPreviewDisplayReplies(filteredReplies, BOARD_REPLIES_PREVIEW_VISIBLE_COUNT);
const directRepliesByParentCid = (() => {
const map = new Map<string, Comment[]>();
@@ -778,7 +780,7 @@ const PostMobile = ({
!isInPendingPostView &&
repliesForRender &&
showReplies &&
filteredReplies.slice(-BOARD_REPLIES_PREVIEW_VISIBLE_COUNT).map((reply) => (
previewDisplayReplies.map((reply) => (
<div key={reply.cid} className={styles.replyContainer}>
<Reply
postReplyCount={replyCount}
+22 -4
View File
@@ -2,15 +2,33 @@ import { BOARD_REPLIES_PREVIEW_VISIBLE_COUNT } from '../constants';
export interface CommentLike {
cid?: string | null;
index?: number;
pendingApproval?: boolean;
state?: string;
timestamp?: number;
}
/**
* From replies sorted by 'new' (newest first), returns the latest N in chronological
* display order (oldest of those first). Handles fewer-than-N replies.
* Returns the latest N replies in chronological display order (oldest first).
*
* `useReplies` can append local account comments to the end of the preview array,
* so we normalize by reply recency first to keep pending/mod-queue items visible in
* board previews.
*/
export function getPreviewDisplayReplies<T extends CommentLike>(replies: T[], visibleCount: number = BOARD_REPLIES_PREVIEW_VISIBLE_COUNT): T[] {
const slice = replies.slice(0, visibleCount);
return [...slice].reverse();
const getRecency = (reply: T): number => {
if (typeof reply?.timestamp === 'number') {
return reply.timestamp;
}
// Pending/local account replies can be missing timestamp early on.
if (typeof reply?.index === 'number' || reply?.pendingApproval || (reply?.state && reply.state !== 'succeeded')) {
return Number.POSITIVE_INFINITY;
}
return Number.NEGATIVE_INFINITY;
};
const newestFirst = [...replies].sort((a, b) => getRecency(b) - getRecency(a));
return newestFirst.slice(0, visibleCount).reverse();
}
export interface ComputeOmittedParams {