From 64b59e42a505456aabff59f18f34741e24c2c851 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 28 Mar 2023 20:33:00 +0800 Subject: [PATCH] Remember replies toggle state during the "session" --- src/pages/status.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/status.jsx b/src/pages/status.jsx index 329b6c55..2047d49e 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -33,6 +33,7 @@ import useTitle from '../utils/useTitle'; const LIMIT = 40; const THREAD_LIMIT = 20; +let cachedRepliesToggle = {}; let cachedStatusesMap = {}; function resetScrollPosition(id) { delete cachedStatusesMap[id]; @@ -293,6 +294,7 @@ function StatusPage() { states.scrollPositions = {}; states.reloadStatusPage = 0; cachedStatusesMap = {}; + cachedRepliesToggle = {}; }; }, []); @@ -870,9 +872,18 @@ function SubComments({ hasManyStatuses, replies, instance, hasParentThread }) { const open = (!hasParentThread || replies.length === 1) && (isBrief || !hasManyStatuses); + const openBefore = cachedRepliesToggle[replies[0].id]; return ( -
+
{ + const { open } = e.target; + // use first reply as ID + cachedRepliesToggle[replies[0].id] = open; + }} + >