From f110ac681263092f8764e688452d13fbd75fe44e Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Mon, 19 Dec 2022 00:19:19 +0800 Subject: [PATCH] Fix flash of un-nested comments --- src/pages/status.jsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/pages/status.jsx b/src/pages/status.jsx index b9d73661..27cff0b7 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -21,8 +21,20 @@ function StatusPage({ id }) { const heroStatusRef = useRef(); useEffect(async () => { - // If id is completely new, reset the whole list - if (!statuses.find((s) => s.id === id)) { + const containsStatus = statuses.find((s) => s.id === id); + const statusesWithSameAccountID = statuses.filter( + (s) => s.accountID === containsStatus?.accountID, + ); + if (statusesWithSameAccountID.length > 1) { + setStatuses( + statusesWithSameAccountID.map((s) => ({ + ...s, + thread: true, + descendant: undefined, + ancestor: undefined, + })), + ); + } else { setStatuses([{ id }]); } @@ -76,10 +88,15 @@ function StatusPage({ id }) { console.log({ ancestors, descendants, nestedDescendants }); const allStatuses = [ - ...ancestors.map((s) => ({ id: s.id, ancestor: true })), - { id }, + ...ancestors.map((s) => ({ + id: s.id, + ancestor: true, + accountID: s.account.id, + })), + { id, accountID: heroStatus.account.id }, ...nestedDescendants.map((s) => ({ id: s.id, + accountID: s.account.id, descendant: true, thread: s.account.id === heroStatus.account.id, replies: s.__replies?.map((r) => r.id),