From 2a959034663db2993d1f468b2752d046329b5ad9 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Sat, 21 Oct 2023 13:45:42 +0200 Subject: [PATCH] chore(all): update multifeed views --- src/components/views/All.jsx | 14 ++++++-------- src/components/views/Board.jsx | 7 ------- src/components/views/Subscriptions.jsx | 14 ++++++-------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/components/views/All.jsx b/src/components/views/All.jsx index b89362f5..b6def524 100755 --- a/src/components/views/All.jsx +++ b/src/components/views/All.jsx @@ -303,22 +303,20 @@ const All = () => { 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); + const existingReplies = flattenedRepliesByThread[thread.cid] || []; + const newReplies = accountComments.filter( + (accountReply) => accountReply.parentCid === thread.cid || existingReplies.some((reply) => reply.cid === accountReply.parentCid), + ); + const combinedReplies = [...existingReplies, ...newReplies].sort((a, b) => a.timestamp - b.timestamp); acc[thread.cid] = { displayedReplies: combinedReplies.slice(0, maxRepliesPerThread), omittedCount: Math.max(combinedReplies.length - maxRepliesPerThread, 0), }; + return acc; }, {}); }, [flattenedRepliesByThread, accountComments, selectedFeed]); diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 9b9f9dac..bb16575f 100755 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -312,18 +312,11 @@ const Board = () => { const maxRepliesPerThread = 5; return selectedFeed.reduce((acc, thread) => { - // 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), diff --git a/src/components/views/Subscriptions.jsx b/src/components/views/Subscriptions.jsx index bdc87928..605003ab 100755 --- a/src/components/views/Subscriptions.jsx +++ b/src/components/views/Subscriptions.jsx @@ -302,22 +302,20 @@ const Subscriptions = () => { 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); + const existingReplies = flattenedRepliesByThread[thread.cid] || []; + const newReplies = accountComments.filter( + (accountReply) => accountReply.parentCid === thread.cid || existingReplies.some((reply) => reply.cid === accountReply.parentCid), + ); + const combinedReplies = [...existingReplies, ...newReplies].sort((a, b) => a.timestamp - b.timestamp); acc[thread.cid] = { displayedReplies: combinedReplies.slice(0, maxRepliesPerThread), omittedCount: Math.max(combinedReplies.length - maxRepliesPerThread, 0), }; + return acc; }, {}); }, [flattenedRepliesByThread, accountComments, selectedFeed]);