From 9df6fd13e762dd51f35c2397bba172ee6a72c495 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 20 May 2025 09:09:58 +0200 Subject: [PATCH 1/2] add method for saving account(settings) tab / rename getLastVisitedWorkspaceTabScreen -> lastVisitedTabPathUtils / update imports / add handling of saved path in NavigationTabBar --- src/CONST.ts | 5 +- .../Navigation/NavigationTabBar/index.tsx | 19 ++++- src/libs/Navigation/NavigationRoot.tsx | 6 +- .../index.native.ts | 22 ------ .../getLastVisitedWorkspaceTabScreen/index.ts | 41 ----------- .../Navigation/helpers/isNavigatorName.ts | 9 ++- .../lastVisitedTabPathUtils/index.native.ts | 36 ++++++++++ .../helpers/lastVisitedTabPathUtils/index.ts | 71 +++++++++++++++++++ src/libs/Navigation/types.ts | 3 +- src/libs/actions/SignInRedirect.ts | 2 +- 10 files changed, 141 insertions(+), 73 deletions(-) delete mode 100644 src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.native.ts delete mode 100644 src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.ts create mode 100644 src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.native.ts create mode 100644 src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts diff --git a/src/CONST.ts b/src/CONST.ts index 4d7049271e78..17752a1f4a7d 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6406,7 +6406,10 @@ const CONST = { ACTIVE_WORKSPACE_ID: 'ACTIVE_WORKSPACE_ID', RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', - LAST_VISITED_WORKSPACES_TAB_PATH: 'LAST_VISITED_WORKSPACES_TAB_PATH', + LAST_VISITED_TAB_PATH: { + WORKSPACES: 'LAST_VISITED_WORKSPACES_TAB_PATH', + SETTINGS: 'LAST_VISITED_SETTINGS_TAB_PATH', + }, }, RESERVATION_TYPE: { diff --git a/src/components/Navigation/NavigationTabBar/index.tsx b/src/components/Navigation/NavigationTabBar/index.tsx index 2e4175353857..bc388bcb00fc 100644 --- a/src/components/Navigation/NavigationTabBar/index.tsx +++ b/src/components/Navigation/NavigationTabBar/index.tsx @@ -23,7 +23,12 @@ import clearSelectedText from '@libs/clearSelectedText/clearSelectedText'; import getPlatform from '@libs/getPlatform'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import {getPreservedNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState'; -import {getLastVisitedWorkspacesTabPath, getLastVisitedWorkspaceTabScreen, getWorkspacesTabStateFromSessionStorage} from '@libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen'; +import { + getLastVisitedTabPath, + getLastVisitedWorkspaceTabScreen, + getSettingsTabStateFromSessionStorage, + getWorkspacesTabStateFromSessionStorage, +} from '@libs/Navigation/helpers/lastVisitedTabPathUtils'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; @@ -121,9 +126,17 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar return; } interceptAnonymousUser(() => { + const settingsTabState = getSettingsTabStateFromSessionStorage(); + if (settingsTabState && !shouldUseNarrowLayout) { + const lastVisitedSettingsRoute = getLastVisitedTabPath(settingsTabState); + if (lastVisitedSettingsRoute) { + Navigation.navigate(lastVisitedSettingsRoute); + return; + } + } Navigation.navigate(ROUTES.SETTINGS); }); - }, [selectedTab]); + }, [selectedTab, shouldUseNarrowLayout]); /** * The settings tab is related to SettingsSplitNavigator and WorkspaceSplitNavigator. @@ -185,7 +198,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar // If the path stored in the session storage leads to a settings screen, we just navigate to it on a wide layout. // On a small screen, we want to go to the page containing the bottom tab bar (ROUTES.SETTINGS or ROUTES.SETTINGS_WORKSPACES) when changing tabs if (workspacesTabState && !shouldUseNarrowLayout) { - const lastVisitedSettingsRoute = getLastVisitedWorkspacesTabPath(workspacesTabState); + const lastVisitedSettingsRoute = getLastVisitedTabPath(workspacesTabState); if (lastVisitedSettingsRoute) { Navigation.navigate(lastVisitedSettingsRoute); return; diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 8e5b5739debd..f2d268ccf667 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -26,8 +26,8 @@ import AppNavigator from './AppNavigator'; import {cleanPreservedNavigatorStates} from './AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import customGetPathFromState from './helpers/customGetPathFromState'; import getAdaptedStateFromPath from './helpers/getAdaptedStateFromPath'; -import {saveWorkspacesTabPathToSessionStorage} from './helpers/getLastVisitedWorkspaceTabScreen'; -import {isWorkspacesTabScreenName} from './helpers/isNavigatorName'; +import {isSettingsTabScreenName, isWorkspacesTabScreenName} from './helpers/isNavigatorName'; +import {saveSettingsTabPathToSessionStorage, saveWorkspacesTabPathToSessionStorage} from './helpers/lastVisitedTabPathUtils'; import {linkingConfig} from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; @@ -74,6 +74,8 @@ function parseAndLogRoute(state: NavigationState) { Navigation.setIsNavigationReady(); if (isWorkspacesTabScreenName(state.routes.at(-1)?.name)) { saveWorkspacesTabPathToSessionStorage(currentPath); + } else if (isSettingsTabScreenName(state.routes.at(-1)?.name)) { + saveSettingsTabPathToSessionStorage(currentPath); } // Fullstory Page navigation tracking diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.native.ts deleted file mode 100644 index b9ed7bd1785d..000000000000 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.native.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type {NavigationState, PartialState} from '@react-navigation/native'; -import type {Route} from '@src/ROUTES'; - -function clearSessionStorage() {} - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function saveWorkspacesTabPathToSessionStorage(url: string) {} - -function getWorkspacesTabStateFromSessionStorage(): PartialState | undefined { - return undefined; -} - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getLastVisitedWorkspacesTabPath(state: NavigationState | PartialState): Route | undefined { - return undefined; -} - -function getLastVisitedWorkspaceTabScreen() { - return undefined; -} - -export {clearSessionStorage, getLastVisitedWorkspaceTabScreen, getLastVisitedWorkspacesTabPath, saveWorkspacesTabPathToSessionStorage, getWorkspacesTabStateFromSessionStorage}; diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.ts deleted file mode 100644 index fed6de39ff11..000000000000 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen/index.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type {NavigationState, PartialState} from '@react-navigation/native'; -import {findFocusedRoute} from '@react-navigation/native'; -import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; -import CONST from '@src/CONST'; -import type {Route} from '@src/ROUTES'; - -function clearSessionStorage() { - sessionStorage.clear(); -} - -function saveWorkspacesTabPathToSessionStorage(url: string) { - sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_WORKSPACES_TAB_PATH, url); -} - -function getWorkspacesTabStateFromSessionStorage(): PartialState | undefined { - const lastVisitedWorkspacesTabPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_WORKSPACES_TAB_PATH); - if (!lastVisitedWorkspacesTabPath) { - return undefined; - } - return getStateFromPath(lastVisitedWorkspacesTabPath as Route); -} - -function getWorkspacesTabScreenNameFromState(state?: PartialState) { - return state?.routes.at(-1)?.state?.routes.at(-1)?.name; -} - -function getLastVisitedWorkspacesTabPath(state: NavigationState | PartialState): Route | undefined { - const lastVisitedWorkspacesTabPath = findFocusedRoute(state)?.path; - if (!lastVisitedWorkspacesTabPath) { - return undefined; - } - return lastVisitedWorkspacesTabPath as Route; -} - -function getLastVisitedWorkspaceTabScreen() { - const workspacesTabState = getWorkspacesTabStateFromSessionStorage(); - const workspacesTabScreenName = getWorkspacesTabScreenNameFromState(workspacesTabState); - return workspacesTabScreenName; -} - -export {clearSessionStorage, getLastVisitedWorkspaceTabScreen, getLastVisitedWorkspacesTabPath, saveWorkspacesTabPathToSessionStorage, getWorkspacesTabStateFromSessionStorage}; diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index f9a713a7caa2..cdba74b1fb83 100644 --- a/src/libs/Navigation/helpers/isNavigatorName.ts +++ b/src/libs/Navigation/helpers/isNavigatorName.ts @@ -1,5 +1,5 @@ import {SIDEBAR_TO_SPLIT, SPLIT_TO_SIDEBAR} from '@libs/Navigation/linkingConfig/RELATIONS'; -import type {FullScreenName, OnboardingFlowName, SplitNavigatorName, SplitNavigatorSidebarScreen, WorkspacesTabScreenName} from '@libs/Navigation/types'; +import type {FullScreenName, OnboardingFlowName, SettingsTabScreenName, SplitNavigatorName, SplitNavigatorSidebarScreen, WorkspacesTabScreenName} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; @@ -20,6 +20,7 @@ const SIDEBARS_SET = new Set(Object.values(SPLIT_TO_SIDEBAR)); const ONBOARDING_SCREENS_SET = new Set(ONBOARDING_SCREENS); const SPLIT_NAVIGATORS_SET = new Set(Object.values(SIDEBAR_TO_SPLIT)); const WORKSPACES_TAB_SET = new Set(Object.values([NAVIGATORS.WORKSPACE_HUB_SPLIT_NAVIGATOR, NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR])); +const SETTINGS_TAB_SET = new Set(Object.values([NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR])); /** * Functions defined below are used to check whether a screen belongs to a specific group. @@ -49,8 +50,12 @@ function isSidebarScreenName(screen: string | undefined) { return checkIfScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); } +function isSettingsTabScreenName(screen: string | undefined) { + return checkIfScreenHasMatchingNameToSetValues(screen, SETTINGS_TAB_SET); +} + function isWorkspacesTabScreenName(screen: string | undefined) { return checkIfScreenHasMatchingNameToSetValues(screen, WORKSPACES_TAB_SET); } -export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName, isWorkspacesTabScreenName}; +export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName, isWorkspacesTabScreenName, isSettingsTabScreenName}; diff --git a/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.native.ts b/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.native.ts new file mode 100644 index 000000000000..9b4bcb0c62b8 --- /dev/null +++ b/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.native.ts @@ -0,0 +1,36 @@ +import type {NavigationState, PartialState} from '@react-navigation/native'; +import type {Route} from '@src/ROUTES'; + +function clearSessionStorage() {} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function saveWorkspacesTabPathToSessionStorage(url: string) {} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function saveSettingsTabPathToSessionStorage(url: string) {} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getLastVisitedTabPath(state: NavigationState | PartialState): Route | undefined { + return undefined; +} + +function getWorkspacesTabStateFromSessionStorage() { + return undefined; +} +function getSettingsTabStateFromSessionStorage() { + return undefined; +} + +function getLastVisitedWorkspaceTabScreen() { + return undefined; +} + +export { + clearSessionStorage, + getLastVisitedWorkspaceTabScreen, + getLastVisitedTabPath, + saveSettingsTabPathToSessionStorage, + getSettingsTabStateFromSessionStorage, + saveWorkspacesTabPathToSessionStorage, + getWorkspacesTabStateFromSessionStorage, +}; diff --git a/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts b/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts new file mode 100644 index 000000000000..73c509b45a7a --- /dev/null +++ b/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts @@ -0,0 +1,71 @@ +import type {NavigationState, PartialState} from '@react-navigation/native'; +import {findFocusedRoute} from '@react-navigation/native'; +import type {ValueOf} from 'type-fest'; +import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; +import CONST from '@src/CONST'; +import type {Route} from '@src/ROUTES'; + +type SessionStorageKey = ValueOf; + +/** + * Clears all session storage data. + */ +function clearSessionStorage() { + sessionStorage.clear(); +} + +/** + * Generic function to save a path to session storage by key + */ +function saveTabPathToSessionStorage(key: SessionStorageKey, url: string) { + sessionStorage.setItem(key, url); +} + +/** + * Converts stored path to navigation state + */ +function getTabStateFromSessionStorage(key: SessionStorageKey) { + const path = sessionStorage.getItem(key) as Route | undefined; + if (!path) { + return undefined; + } + return getStateFromPath(path); +} + +/** + * Generic function to extract the path from currently focused route + */ +function getLastVisitedTabPath(state: NavigationState | PartialState): Route | undefined { + return findFocusedRoute(state)?.path as Route | undefined; +} + +function saveWorkspacesTabPathToSessionStorage(url: string) { + saveTabPathToSessionStorage(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_TAB_PATH.WORKSPACES, url); +} + +function getWorkspacesTabStateFromSessionStorage() { + return getTabStateFromSessionStorage(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_TAB_PATH.WORKSPACES); +} + +function saveSettingsTabPathToSessionStorage(url: string) { + saveTabPathToSessionStorage(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_TAB_PATH.SETTINGS, url); +} + +function getSettingsTabStateFromSessionStorage() { + return getTabStateFromSessionStorage(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_TAB_PATH.SETTINGS); +} + +function getLastVisitedWorkspaceTabScreen() { + const workspacesTabState = getWorkspacesTabStateFromSessionStorage(); + return workspacesTabState?.routes?.at(-1)?.state?.routes?.at(-1)?.name; +} + +export { + clearSessionStorage, + getLastVisitedWorkspaceTabScreen, + getLastVisitedTabPath, + saveSettingsTabPathToSessionStorage, + getSettingsTabStateFromSessionStorage, + saveWorkspacesTabPathToSessionStorage, + getWorkspacesTabStateFromSessionStorage, +}; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 53cedc190517..b3f8393eb04b 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -2050,7 +2050,7 @@ type FullScreenName = SplitNavigatorName | SearchFullscreenNavigatorName; type WorkspacesTabScreenName = typeof NAVIGATORS.WORKSPACE_HUB_SPLIT_NAVIGATOR | typeof NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR; type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; - +type SettingsTabScreenName = typeof NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace ReactNavigation { @@ -2131,6 +2131,7 @@ export type { ScheduleCallParamList, TestDriveModalNavigatorParamList, WorkspaceScreenName, + SettingsTabScreenName, TestDriveDemoNavigatorParamList, WorkspacesTabScreenName, }; diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index a02bbbea7546..d0cfc5352156 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -1,6 +1,6 @@ import Onyx from 'react-native-onyx'; import {getMicroSecondOnyxErrorWithMessage} from '@libs/ErrorUtils'; -import {clearSessionStorage} from '@libs/Navigation/helpers/getLastVisitedWorkspaceTabScreen'; +import {clearSessionStorage} from '@libs/Navigation/helpers/lastVisitedTabPathUtils'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; import {clearAllPolicies} from './Policy/Policy'; From 9ebda985d605d204ecd33fc27ab13ffdc92a65b7 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 20 May 2025 14:25:09 +0200 Subject: [PATCH 2/2] rename type of session storage keys (tab path) / remove unnecesary functions / update types --- src/libs/Navigation/NavigationRoot.tsx | 4 ++-- src/libs/Navigation/helpers/isNavigatorName.ts | 11 +++-------- .../helpers/lastVisitedTabPathUtils/index.ts | 14 +++++++++----- src/libs/Navigation/types.ts | 8 ++++---- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index f2d268ccf667..25d093c5d579 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -26,7 +26,7 @@ import AppNavigator from './AppNavigator'; import {cleanPreservedNavigatorStates} from './AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import customGetPathFromState from './helpers/customGetPathFromState'; import getAdaptedStateFromPath from './helpers/getAdaptedStateFromPath'; -import {isSettingsTabScreenName, isWorkspacesTabScreenName} from './helpers/isNavigatorName'; +import {isWorkspacesTabScreenName} from './helpers/isNavigatorName'; import {saveSettingsTabPathToSessionStorage, saveWorkspacesTabPathToSessionStorage} from './helpers/lastVisitedTabPathUtils'; import {linkingConfig} from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; @@ -74,7 +74,7 @@ function parseAndLogRoute(state: NavigationState) { Navigation.setIsNavigationReady(); if (isWorkspacesTabScreenName(state.routes.at(-1)?.name)) { saveWorkspacesTabPathToSessionStorage(currentPath); - } else if (isSettingsTabScreenName(state.routes.at(-1)?.name)) { + } else if (state.routes.at(-1)?.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR) { saveSettingsTabPathToSessionStorage(currentPath); } diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index cdba74b1fb83..1f2e01358720 100644 --- a/src/libs/Navigation/helpers/isNavigatorName.ts +++ b/src/libs/Navigation/helpers/isNavigatorName.ts @@ -1,5 +1,5 @@ import {SIDEBAR_TO_SPLIT, SPLIT_TO_SIDEBAR} from '@libs/Navigation/linkingConfig/RELATIONS'; -import type {FullScreenName, OnboardingFlowName, SettingsTabScreenName, SplitNavigatorName, SplitNavigatorSidebarScreen, WorkspacesTabScreenName} from '@libs/Navigation/types'; +import type {FullScreenName, OnboardingFlowName, SplitNavigatorName, SplitNavigatorSidebarScreen, WorkspacesTabNavigatorName} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; @@ -20,7 +20,6 @@ const SIDEBARS_SET = new Set(Object.values(SPLIT_TO_SIDEBAR)); const ONBOARDING_SCREENS_SET = new Set(ONBOARDING_SCREENS); const SPLIT_NAVIGATORS_SET = new Set(Object.values(SIDEBAR_TO_SPLIT)); const WORKSPACES_TAB_SET = new Set(Object.values([NAVIGATORS.WORKSPACE_HUB_SPLIT_NAVIGATOR, NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR])); -const SETTINGS_TAB_SET = new Set(Object.values([NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR])); /** * Functions defined below are used to check whether a screen belongs to a specific group. @@ -50,12 +49,8 @@ function isSidebarScreenName(screen: string | undefined) { return checkIfScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); } -function isSettingsTabScreenName(screen: string | undefined) { - return checkIfScreenHasMatchingNameToSetValues(screen, SETTINGS_TAB_SET); -} - function isWorkspacesTabScreenName(screen: string | undefined) { - return checkIfScreenHasMatchingNameToSetValues(screen, WORKSPACES_TAB_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, WORKSPACES_TAB_SET); } -export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName, isWorkspacesTabScreenName, isSettingsTabScreenName}; +export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName, isWorkspacesTabScreenName}; diff --git a/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts b/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts index 73c509b45a7a..b422ea0e4d5a 100644 --- a/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts +++ b/src/libs/Navigation/helpers/lastVisitedTabPathUtils/index.ts @@ -5,7 +5,7 @@ import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; import CONST from '@src/CONST'; import type {Route} from '@src/ROUTES'; -type SessionStorageKey = ValueOf; +type LastVisitedTabPathKey = ValueOf; /** * Clears all session storage data. @@ -17,14 +17,14 @@ function clearSessionStorage() { /** * Generic function to save a path to session storage by key */ -function saveTabPathToSessionStorage(key: SessionStorageKey, url: string) { +function saveTabPathToSessionStorage(key: LastVisitedTabPathKey, url: string) { sessionStorage.setItem(key, url); } /** * Converts stored path to navigation state */ -function getTabStateFromSessionStorage(key: SessionStorageKey) { +function getTabStateFromSessionStorage(key: LastVisitedTabPathKey) { const path = sessionStorage.getItem(key) as Route | undefined; if (!path) { return undefined; @@ -35,8 +35,12 @@ function getTabStateFromSessionStorage(key: SessionStorageKey) { /** * Generic function to extract the path from currently focused route */ -function getLastVisitedTabPath(state: NavigationState | PartialState): Route | undefined { - return findFocusedRoute(state)?.path as Route | undefined; +function getLastVisitedTabPath(state: NavigationState | PartialState) { + const focusedRoute = findFocusedRoute(state); + if (!focusedRoute) { + return undefined; + } + return focusedRoute.path as Route; } function saveWorkspacesTabPathToSessionStorage(url: string) { diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index b3f8393eb04b..0dcfcd1427a3 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -2047,10 +2047,11 @@ type SearchFullscreenNavigatorName = typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGAT type FullScreenName = SplitNavigatorName | SearchFullscreenNavigatorName; -type WorkspacesTabScreenName = typeof NAVIGATORS.WORKSPACE_HUB_SPLIT_NAVIGATOR | typeof NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR; +// There are two split navigators which can be displayed when the Workspaces tab is selected +type WorkspacesTabNavigatorName = typeof NAVIGATORS.WORKSPACE_HUB_SPLIT_NAVIGATOR | typeof NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR; type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; -type SettingsTabScreenName = typeof NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR; + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace ReactNavigation { @@ -2131,7 +2132,6 @@ export type { ScheduleCallParamList, TestDriveModalNavigatorParamList, WorkspaceScreenName, - SettingsTabScreenName, TestDriveDemoNavigatorParamList, - WorkspacesTabScreenName, + WorkspacesTabNavigatorName, };