Files
5chan/src/hooks/use-count-links-in-replies.ts
T
Tommaso CasaburiandGitHub 371de88e22 chore(architecture): finish refactor audit
Merge the architecture audit refactors and follow-up UX fixes: remove release notes from generated LLM context, keep author edit controls delete-only, stabilize board refresh rendering, and address review feedback for role loading, refresh holds, moderation actions, and P2P stats polling.
2026-06-23 18:48:47 +07:00

21 lines
658 B
TypeScript

import { useMemo } from 'react';
import { Comment } from '@bitsocial/bitsocial-react-hooks';
import { flattenCommentsPages } from '../lib/bitsocial-internals/utils';
const useCountLinksInReplies = (comment: Comment | undefined, firstXReplies?: number) => {
let linkCount = 0;
const flattenedReplies = useMemo(() => flattenCommentsPages(comment?.replies), [comment?.replies]);
const repliesToConsider = firstXReplies !== undefined ? flattenedReplies.slice(0, firstXReplies) : flattenedReplies;
for (let reply of repliesToConsider) {
if (reply.link) {
linkCount++;
}
}
return linkCount;
};
export default useCountLinksInReplies;