From 0c45bed333885622276649deb2370191299d2624 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 17 Jul 2023 17:32:46 +0200 Subject: [PATCH] =?UTF-8?q?[Glitch]=20Fix=20=E2=80=9CBack=E2=80=9D=20butto?= =?UTF-8?q?n=20sometimes=20redirecting=20out=20of=20Mastodon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port a442a1d1c69e5d477ca1c05f0bc5fc0f6894b223 to glitch-soc Signed-off-by: Claire --- .../glitch/components/column_back_button.jsx | 4 +-- .../glitch/components/column_header.jsx | 7 ++--- .../flavours/glitch/components/router.tsx | 31 ++++++++++++++++--- .../flavours/glitch/features/ui/index.jsx | 9 +++--- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/javascript/flavours/glitch/components/column_back_button.jsx b/app/javascript/flavours/glitch/components/column_back_button.jsx index 0934d4b33..5a11a3d5e 100644 --- a/app/javascript/flavours/glitch/components/column_back_button.jsx +++ b/app/javascript/flavours/glitch/components/column_back_button.jsx @@ -20,9 +20,7 @@ export default class ColumnBackButton extends PureComponent { handleClick = () => { const { router } = this.context; - // Check if there is a previous page in the app to go back to per https://stackoverflow.com/a/70532858/9703201 - // When upgrading to V6, check `location.key !== 'default'` instead per https://github.com/remix-run/history/blob/main/docs/api-reference.md#location - if (router.route.location.key) { + if (router.history.location?.state?.fromMastodon) { router.history.goBack(); } else { router.history.push('/'); diff --git a/app/javascript/flavours/glitch/components/column_header.jsx b/app/javascript/flavours/glitch/components/column_header.jsx index e8c056c0b..8a68036e9 100644 --- a/app/javascript/flavours/glitch/components/column_header.jsx +++ b/app/javascript/flavours/glitch/components/column_header.jsx @@ -65,9 +65,7 @@ class ColumnHeader extends PureComponent { handleBackClick = () => { const { router } = this.context; - // Check if there is a previous page in the app to go back to per https://stackoverflow.com/a/70532858/9703201 - // When upgrading to V6, check `location.key !== 'default'` instead per https://github.com/remix-run/history/blob/main/docs/api-reference.md#location - if (router.route.location.key) { + if (router.history.location?.state?.fromMastodon) { router.history.goBack(); } else { router.history.push('/'); @@ -87,6 +85,7 @@ class ColumnHeader extends PureComponent { }; render () { + const { router } = this.context; const { title, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder, appendContent, collapseIssues } = this.props; const { collapsed, animating } = this.state; @@ -130,7 +129,7 @@ class ColumnHeader extends PureComponent { pinButton = ; } - if (!pinned && (multiColumn || showBackButton)) { + if (!pinned && ((multiColumn && router.history.location?.state?.fromMastodon) || showBackButton)) { backButton = (