mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(use-replies.ts): flatten and display replies of replies not yet published
This commit is contained in:
@@ -3,11 +3,22 @@ import { Comment, useAccountComments } from '@plebbit/plebbit-react-hooks';
|
|||||||
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils';
|
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils';
|
||||||
|
|
||||||
const useRepliesAndAccountReplies = (comment: Comment) => {
|
const useRepliesAndAccountReplies = (comment: Comment) => {
|
||||||
// filter only the parent cid
|
// flatten all replies including nested ones from the original comment
|
||||||
const filter = useCallback((accountComment: Comment) => accountComment.parentCid === (comment?.cid || 'n/a'), [comment?.cid]);
|
|
||||||
const { accountComments } = useAccountComments({ filter });
|
|
||||||
const flattenedReplies = useMemo(() => flattenCommentsPages(comment.replies), [comment.replies]);
|
const flattenedReplies = useMemo(() => flattenCommentsPages(comment.replies), [comment.replies]);
|
||||||
|
|
||||||
|
// gemerate a Set of CIDs from flattened replies for quick lookup
|
||||||
|
const replyCids = useMemo(() => new Set(flattenedReplies.map((reply) => reply.cid)), [flattenedReplies]);
|
||||||
|
|
||||||
|
// filter against all CIDs in flattened replies
|
||||||
|
const filter = useCallback(
|
||||||
|
(accountComment: Comment) => {
|
||||||
|
return replyCids.has(accountComment.parentCid);
|
||||||
|
},
|
||||||
|
[replyCids],
|
||||||
|
);
|
||||||
|
|
||||||
|
const { accountComments } = useAccountComments({ filter });
|
||||||
|
|
||||||
// the account's replies have a delay before getting published, so get them locally from accountComments instead
|
// the account's replies have a delay before getting published, so get them locally from accountComments instead
|
||||||
const accountRepliesNotYetPublished = useMemo(() => {
|
const accountRepliesNotYetPublished = useMemo(() => {
|
||||||
const replies = flattenedReplies || [];
|
const replies = flattenedReplies || [];
|
||||||
|
|||||||
Reference in New Issue
Block a user