mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat: add "hidden threads" counter and button in catalog and board view, store and hook
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Comment, useAccount, useComments } from '@plebbit/plebbit-react-hooks';
|
||||
|
||||
const useBlockedComments = (subplebbitAddress?: string): Comment[] => {
|
||||
const account = useAccount();
|
||||
|
||||
const commentCids = useMemo(() => {
|
||||
return Object.entries(account.blockedAddresses)
|
||||
.filter(([address, isBlocked]) => {
|
||||
const isValidCommentCid = !address || /^Qm[a-zA-Z0-9]{44}$/.test(address);
|
||||
return isBlocked && isValidCommentCid;
|
||||
})
|
||||
.map(([address]) => address);
|
||||
}, [account]);
|
||||
|
||||
const { comments } = useComments({ commentCids });
|
||||
|
||||
const filteredComments = useMemo(() => {
|
||||
const validComments = comments.filter((comment): comment is Comment => comment !== undefined);
|
||||
|
||||
if (!subplebbitAddress) {
|
||||
return validComments;
|
||||
}
|
||||
|
||||
return validComments.filter((comment: Comment) => comment.subplebbitAddress === subplebbitAddress);
|
||||
}, [comments, subplebbitAddress]);
|
||||
|
||||
return filteredComments;
|
||||
};
|
||||
|
||||
export default useBlockedComments;
|
||||
Reference in New Issue
Block a user