feat: add "hidden threads" counter and button in catalog and board view, store and hook

This commit is contained in:
Tom (plebeius.eth)
2024-05-30 18:01:37 +02:00
parent 32f52200b7
commit fd092f1bee
10 changed files with 153 additions and 40 deletions
+31
View File
@@ -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;