feat(post): add links and media info, including embed

This commit is contained in:
plebeius.eth
2024-03-22 16:15:38 +01:00
parent f1af55edf0
commit d0a3e959fc
10 changed files with 572 additions and 53 deletions
+29
View File
@@ -0,0 +1,29 @@
import { useMemo, useCallback } from 'react';
import { Comment, useAccountComments } from '@plebbit/plebbit-react-hooks';
const useRepliesAndAccountReplies = (comment: Comment) => {
// filter only the parent cid
const filter = useCallback((accountComment: Comment) => accountComment.parentCid === (comment?.cid || 'n/a'), [comment?.cid]);
const { accountComments } = useAccountComments({ filter });
// the account's replies have a delay before getting published, so get them locally from accountComments instead
const accountRepliesNotYetPublished = useMemo(() => {
const replies = comment?.replies?.pages?.topAll?.comments || [];
const replyCids = new Set(replies.map((reply: Comment) => reply?.cid));
// filter out the account comments already in comment.replies, so they don't appear twice
return accountComments.filter((accountReply) => !replyCids.has(accountReply?.cid));
}, [comment?.replies?.pages?.topAll?.comments, accountComments]);
const repliesAndNotYetPublishedReplies = useMemo(() => {
return [
// put the author's unpublished replies at the top, latest first (reverse)
...accountRepliesNotYetPublished.reverse(),
// put the published replies after,
...(comment?.replies?.pages?.topAll?.comments || []),
];
}, [comment?.replies?.pages?.topAll?.comments, accountRepliesNotYetPublished]);
return repliesAndNotYetPublishedReplies;
};
export default useRepliesAndAccountReplies;