From 81170c6d05a575785e5889aff29a8601a6a8ac04 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 21 Jan 2023 19:52:51 +0800 Subject: [PATCH] When clicked, don't use cached scroll position --- src/components/link.jsx | 1 + src/pages/status.jsx | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/link.jsx b/src/components/link.jsx index 3dee227d..39698d26 100644 --- a/src/components/link.jsx +++ b/src/components/link.jsx @@ -25,6 +25,7 @@ const Link = (props) => { class={`${props.class || ''} ${isActive ? 'is-active' : ''}`} onClick={() => { if (routerLocation) states.prevLocation = routerLocation; + props.onClick?.(); }} /> ); diff --git a/src/pages/status.jsx b/src/pages/status.jsx index 66980424..a98b1afc 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -24,6 +24,10 @@ import useTitle from '../utils/useTitle'; const LIMIT = 40; +function resetScrollPosition(id) { + delete states.scrollPositions[id]; +} + function StatusPage() { const { id } = useParams(); const location = useLocation(); @@ -190,6 +194,7 @@ function StatusPage() { console.debug('scrollPosition', scrollPosition); if (!!scrollPosition) { console.debug('Case 1', { + id, scrollPosition, }); scrollableRef.current.scrollTop = scrollPosition; @@ -420,7 +425,13 @@ function StatusPage() { ) : ( - + { + resetScrollPosition(statusID); + }} + > {}, -}) { +function SubComments({ hasManyStatuses, replies }) { // If less than or 2 replies and total number of characters of content from replies is less than 500 let isBrief = false; if (replies.length <= 2) { @@ -551,7 +558,9 @@ function SubComments({ { + resetScrollPosition(r.id); + }} > {r.repliesCount > 0 && (