mirror of
https://github.com/plebbit/seedit.git
synced 2026-04-20 07:08:43 -04:00
make useReplies page access dynamic to improve API compatibility
This commit is contained in:
@@ -8,20 +8,25 @@ const useRepliesAndAccountReplies = (comment: Comment) => {
|
||||
|
||||
// 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?.best?.comments || [];
|
||||
const replyCids = new Set(replies.map((reply: Comment) => reply?.cid));
|
||||
const pageValues = comment?.replies?.pages ? Object.values(comment.replies.pages) : [];
|
||||
const firstPageObject = pageValues[0] as { comments?: Comment[] } | undefined;
|
||||
const publishedComments = firstPageObject?.comments || [];
|
||||
const replyCids = new Set(publishedComments.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?.best?.comments, accountComments]);
|
||||
}, [comment?.replies?.pages, accountComments]);
|
||||
|
||||
const repliesAndNotYetPublishedReplies = useMemo(() => {
|
||||
const pageValues = comment?.replies?.pages ? Object.values(comment.replies.pages) : [];
|
||||
const firstPageObject = pageValues[0] as { comments?: Comment[] } | undefined;
|
||||
const publishedComments = firstPageObject?.comments || [];
|
||||
return [
|
||||
// put the author's unpublished replies at the top, latest first (reverse)
|
||||
...accountRepliesNotYetPublished.reverse(),
|
||||
// put the published replies after,
|
||||
...(comment?.replies?.pages?.best?.comments || []),
|
||||
...publishedComments,
|
||||
];
|
||||
}, [comment?.replies?.pages?.best?.comments, accountRepliesNotYetPublished]);
|
||||
}, [comment?.replies?.pages, accountRepliesNotYetPublished]);
|
||||
|
||||
return repliesAndNotYetPublishedReplies;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user