mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
chore(all): update multifeed views
This commit is contained in:
@@ -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]);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user