mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(board-replies): include pending and mod-queue account comments in 5-reply preview
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user