From 04a81cc59bb90f3ff5036924f5985d905e109d24 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Nov 2023 20:58:40 +0700 Subject: [PATCH 1/3] fix: 31688 Notification preferences page appears again after refreshing the page --- src/libs/actions/Report.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 9bc2aa1b3f2f..e8266fe66272 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2016,7 +2016,9 @@ function openReportFromDeepLink(url, isAuthenticated) { Session.signOutAndRedirectToSignIn(); return; } - Navigation.navigate(route, CONST.NAVIGATION.ACTION_TYPE.PUSH); + if (!Navigation.isActiveRoute(route)) { + Navigation.navigate(route, CONST.NAVIGATION.ACTION_TYPE.PUSH); + } }); }); }); From 370dafb79ef7c6853243429e09a2c092acf385ee Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Nov 2023 22:35:20 +0700 Subject: [PATCH 2/3] refactor --- src/libs/Navigation/Navigation.js | 2 +- src/libs/Navigation/linkTo.js | 4 ++-- src/libs/actions/Report.js | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 2629d36999bf..775c852a9f12 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -111,7 +111,7 @@ function navigate(route = ROUTES.HOME, type) { pendingRoute = route; return; } - linkTo(navigationRef.current, route, type); + linkTo(navigationRef.current, route, type, isActiveRoute(route)); } /** diff --git a/src/libs/Navigation/linkTo.js b/src/libs/Navigation/linkTo.js index 55bd4b31dbdf..ca87a0d7b79c 100644 --- a/src/libs/Navigation/linkTo.js +++ b/src/libs/Navigation/linkTo.js @@ -41,7 +41,7 @@ function getMinimalAction(action, state) { return currentAction; } -export default function linkTo(navigation, path, type) { +export default function linkTo(navigation, path, type, isActiveRoute) { if (navigation === undefined) { throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?"); } @@ -86,7 +86,7 @@ export default function linkTo(navigation, path, type) { // There are situations where a route already exists on the current navigation stack // But we want to push the same route instead of going back in the stack // Which would break the user navigation history - if (type === CONST.NAVIGATION.ACTION_TYPE.PUSH) { + if (!isActiveRoute && type === CONST.NAVIGATION.ACTION_TYPE.PUSH) { minimalAction.type = CONST.NAVIGATION.ACTION_TYPE.PUSH; } // There are situations when the user is trying to access a route which he has no access to diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index e8266fe66272..9bc2aa1b3f2f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2016,9 +2016,7 @@ function openReportFromDeepLink(url, isAuthenticated) { Session.signOutAndRedirectToSignIn(); return; } - if (!Navigation.isActiveRoute(route)) { - Navigation.navigate(route, CONST.NAVIGATION.ACTION_TYPE.PUSH); - } + Navigation.navigate(route, CONST.NAVIGATION.ACTION_TYPE.PUSH); }); }); }); From b6abdd4b87fbda2ee50bea82b1c754b635d3563d Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Nov 2023 23:06:45 +0700 Subject: [PATCH 3/3] refactor --- src/libs/Navigation/Navigation.js | 68 +++++++++++++++---------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 775c852a9f12..bfc0f509373e 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -98,6 +98,40 @@ function getDistanceFromPathInRootNavigator(path) { return -1; } +/** + * Returns the current active route + * @returns {String} + */ +function getActiveRoute() { + const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute(); + const currentRouteHasName = lodashGet(currentRoute, 'name', false); + if (!currentRouteHasName) { + return ''; + } + + const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config); + + if (routeFromState) { + return routeFromState; + } + + return ''; +} + +/** + * Check whether the passed route is currently Active or not. + * + * Building path with getPathFromState since navigationRef.current.getCurrentRoute().path + * is undefined in the first navigation. + * + * @param {String} routePath Path to check + * @return {Boolean} is active + */ +function isActiveRoute(routePath) { + // We remove First forward slash from the URL before matching + return getActiveRoute().substring(1) === routePath; +} + /** * Main navigation method for redirecting to a route. * @param {String} route @@ -221,26 +255,6 @@ function dismissModal(targetReportID) { } } -/** - * Returns the current active route - * @returns {String} - */ -function getActiveRoute() { - const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute(); - const currentRouteHasName = lodashGet(currentRoute, 'name', false); - if (!currentRouteHasName) { - return ''; - } - - const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config); - - if (routeFromState) { - return routeFromState; - } - - return ''; -} - /** * Returns the current active route without the URL params * @returns {String} @@ -265,20 +279,6 @@ function getRouteNameFromStateEvent(event) { } } -/** - * Check whether the passed route is currently Active or not. - * - * Building path with getPathFromState since navigationRef.current.getCurrentRoute().path - * is undefined in the first navigation. - * - * @param {String} routePath Path to check - * @return {Boolean} is active - */ -function isActiveRoute(routePath) { - // We remove First forward slash from the URL before matching - return getActiveRoute().substring(1) === routePath; -} - /** * Navigate to the route that we originally intended to go to * but the NavigationContainer was not ready when navigate() was called