More adjustment to auto-collapsing logic

This commit is contained in:
Lim Chee Aun 2023-05-09 22:29:18 +08:00
parent d264af14f1
commit 4d5c0f1f5d

View file

@ -596,8 +596,6 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
}); });
}, []); }, []);
const totalWeight = statuses?.length;
return ( return (
<div <div
tabIndex="-1" tabIndex="-1"
@ -911,7 +909,7 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
replies={replies} replies={replies}
hasParentThread={thread} hasParentThread={thread}
level={1} level={1}
accWeight={totalWeight} accWeight={weight}
/> />
)} )}
{uiState === 'loading' && {uiState === 'loading' &&
@ -1010,8 +1008,14 @@ function SubComments({ replies, instance, hasParentThread, level, accWeight }) {
.filter((a, i, arr) => arr.findIndex((b) => b.id === a.id) === i) .filter((a, i, arr) => arr.findIndex((b) => b.id === a.id) === i)
.slice(0, 3); .slice(0, 3);
const totalWeight = useMemo(() => {
return replies?.reduce((acc, reply) => {
return acc + reply?.weight;
}, accWeight);
}, [accWeight, replies?.length]);
let open = false; let open = false;
if (accWeight <= MAX_WEIGHT) { if (totalWeight <= MAX_WEIGHT) {
open = true; open = true;
} else if (!hasParentThread && totalComments === 1) { } else if (!hasParentThread && totalComments === 1) {
const shortReply = calcStatusWeight(replies[0]) < 2; const shortReply = calcStatusWeight(replies[0]) < 2;
@ -1041,12 +1045,6 @@ function SubComments({ replies, instance, hasParentThread, level, accWeight }) {
}; };
}, []); }, []);
const totalWeight = useMemo(() => {
return replies?.reduce((acc, reply) => {
return acc + reply?.weight;
}, 0);
}, [replies?.length]);
return ( return (
<details <details
ref={detailsRef} ref={detailsRef}
@ -1123,7 +1121,7 @@ function SubComments({ replies, instance, hasParentThread, level, accWeight }) {
instance={instance} instance={instance}
replies={r.replies} replies={r.replies}
level={level + 1} level={level + 1}
accWeight={!open ? totalWeight : accWeight + totalWeight} accWeight={!open ? r.weight : totalWeight}
/> />
)} )}
</li> </li>