2024-04-02 12:23:18 +02:00
|
|
|
import { useMemo } from 'react';
|
2026-04-20 22:11:36 +07:00
|
|
|
import { Comment } from '@bitsocial/bitsocial-react-hooks';
|
|
|
|
|
import { flattenCommentsPages } from '@bitsocial/bitsocial-react-hooks/dist/lib/utils';
|
2024-04-02 12:23:18 +02:00
|
|
|
|
2026-04-24 15:48:07 +07:00
|
|
|
const useCountLinksInReplies = (comment: Comment | undefined, firstXReplies?: number) => {
|
2024-04-02 12:23:18 +02:00
|
|
|
let linkCount = 0;
|
2024-06-15 12:37:45 +02:00
|
|
|
const flattenedReplies = useMemo(() => flattenCommentsPages(comment?.replies), [comment?.replies]);
|
2024-04-02 12:23:18 +02:00
|
|
|
|
|
|
|
|
const repliesToConsider = firstXReplies !== undefined ? flattenedReplies.slice(0, firstXReplies) : flattenedReplies;
|
|
|
|
|
|
|
|
|
|
for (let reply of repliesToConsider) {
|
|
|
|
|
if (reply.link) {
|
|
|
|
|
linkCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return linkCount;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default useCountLinksInReplies;
|