mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
add counter for omitted replies and links in replies
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Comment } from '@plebbit/plebbit-react-hooks';
|
||||
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils';
|
||||
|
||||
const useCountLinksInReplies = (comment: Comment, 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;
|
||||
Reference in New Issue
Block a user