fix(thread): replying to a reply didn't show the pending comment

This commit is contained in:
plebeius.eth
2023-10-21 13:39:42 +02:00
parent 87a019ed4f
commit 9f5f2d1663
2 changed files with 16 additions and 9 deletions
+13 -8
View File
@@ -308,22 +308,27 @@ const Board = () => {
const filter = useCallback((accountComment) => allParentCids.has(accountComment.parentCid), [allParentCids]);
const { accountComments } = useAccountComments({ filter });
const filteredRepliesByThread = useMemo(() => {
const maxRepliesPerThread = 5;
const accountRepliesNotYetInCommentReplies = selectedFeed.reduce((acc, thread) => {
const replyCids = new Set(flattenedRepliesByThread[thread.cid].map((reply) => reply.cid));
acc[thread.cid] = accountComments.filter((accountReply) => !replyCids.has(accountReply.cid) && accountReply.parentCid === thread.cid);
return acc;
}, {});
return selectedFeed.reduce((acc, thread) => {
const combinedReplies = [...flattenedRepliesByThread[thread.cid], ...accountRepliesNotYetInCommentReplies[thread.cid]].sort((a, b) => a.timestamp - b.timestamp);
// Get replies that are already in the thread
const existingReplies = flattenedRepliesByThread[thread.cid] || [];
// Get replies that belong to this thread but are not yet in the thread
const newReplies = accountComments.filter(
(accountReply) => accountReply.parentCid === thread.cid || existingReplies.some((reply) => reply.cid === accountReply.parentCid),
);
// Combine and sort all the replies
const combinedReplies = [...existingReplies, ...newReplies].sort((a, b) => a.timestamp - b.timestamp);
// Limit the number of displayed replies and count the omitted ones
acc[thread.cid] = {
displayedReplies: combinedReplies.slice(0, maxRepliesPerThread),
omittedCount: Math.max(combinedReplies.length - maxRepliesPerThread, 0),
};
return acc;
}, {});
}, [flattenedRepliesByThread, accountComments, selectedFeed]);
+3 -1
View File
@@ -306,7 +306,9 @@ const Thread = () => {
const accountRepliesNotYetInCommentReplies = useMemo(() => {
const commentReplyCids = new Set(flattenedReplies.map((reply) => reply.cid));
return accountComments.filter((accountReply) => {
return !commentReplyCids.has(accountReply.cid) && accountReply.parentCid === selectedThread;
return (
!commentReplyCids.has(accountReply.cid) && (accountReply.parentCid === selectedThread || flattenedReplies.some((reply) => reply.cid === accountReply.parentCid))
);
});
}, [flattenedReplies, accountComments, selectedThread]);