From b63d5265903b9d66bbbcbddff8b8ad280e03200f Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 9 Oct 2023 12:21:02 +0200 Subject: [PATCH] [Glitch] Fix clicking on already-opened thread post scrolling to the top of the thread Port c310374a2f83a890520ace50e41c1e3d046e15e1 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/features/status/index.jsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/features/status/index.jsx b/app/javascript/flavours/glitch/features/status/index.jsx index 457314db66..c8bb2c2554 100644 --- a/app/javascript/flavours/glitch/features/status/index.jsx +++ b/app/javascript/flavours/glitch/features/status/index.jsx @@ -642,6 +642,22 @@ class Status extends ImmutablePureComponent { this.setState({ fullscreen: isFullscreen() }); }; + shouldUpdateScroll = (prevRouterProps, { location }) => { + // Do not change scroll when opening a modal + if (location.state?.mastodonModalKey && location.state?.mastodonModalKey !== prevRouterProps?.location?.state?.mastodonModalKey) { + return false; + } + + // Scroll to focused post if it is loaded + const child = this.node?.querySelector('.detailed-status__wrapper'); + if (child) { + return [0, child.offsetTop]; + } + + // Do not scroll otherwise, `componentDidUpdate` will take care of that + return false; + }; + render () { let ancestors, descendants; const { isLoading, status, settings, ancestorsIds, descendantsIds, intl, domain, multiColumn, pictureInPicture } = this.props; @@ -701,7 +717,7 @@ class Status extends ImmutablePureComponent { )} /> - +
{ancestors}