From 372e86415b0b7b34a7cf4f0c9530a78c988af981 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 27 Oct 2023 14:16:38 +0800 Subject: [PATCH] Test fix scroll position when opening media on the side --- src/pages/status.jsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pages/status.jsx b/src/pages/status.jsx index da64e59c..13be215a 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -167,6 +167,7 @@ function StatusPage(params) { function StatusThread({ id, closeLink = '/', instance: propInstance }) { const [searchParams, setSearchParams] = useSearchParams(); const mediaParam = searchParams.get('media'); + const mediaStatusID = searchParams.get('mediaStatusID'); const showMedia = parseInt(mediaParam, 10) > 0; const firstLoad = useRef(!states.prevLocation && history.length === 1); const [viewMode, setViewMode] = useState( @@ -657,6 +658,23 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) { resetScrollPosition(status.id); }, []); + useEffect(() => { + let timer; + if (mediaStatusID && showMedia) { + timer = setTimeout(() => { + const status = scrollableRef.current?.querySelector( + `.status-link[href*="/${mediaStatusID}"]`, + ); + if (status) { + status.scrollIntoView(scrollIntoViewOptions); + } + }, 400); // After CSS transition + } + return () => { + clearTimeout(timer); + }; + }, [mediaStatusID, showMedia]); + const renderStatus = useCallback( (status) => { const {