From 049c8b26f6e1f6c91399794990b5ff959affcffa Mon Sep 17 00:00:00 2001 From: borys3kk Date: Wed, 19 Mar 2025 16:36:54 +0100 Subject: [PATCH 01/12] added path saving to local storage --- src/CONST.ts | 1 + .../Navigation/BottomTabBar/index.tsx | 8 +++++++- src/libs/Navigation/NavigationRoot.tsx | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 8aaeca6443fda..8ffffbe573b4c 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6312,6 +6312,7 @@ const CONST = { ACTIVE_WORKSPACE_ID: 'ACTIVE_WORKSPACE_ID', RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', + LAST_VISITED_SETTINGS_PATH: 'LAST_VISITED_SETTINGS_PATH' }, RESERVATION_TYPE: { diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index a104479c7eb39..c5d0569b01d38 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -32,7 +32,7 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; +import ROUTES, {Route} from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import BOTTOM_TABS from './BOTTOM_TABS'; @@ -114,6 +114,12 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps * If the user clicks on the settings tab while on this tab, this button should go back to the previous screen within the tab. */ const showSettingsPage = useCallback(() => { + const LAST_VISITED_SETTINGS_PATH = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH) as Route | null; + console.log('path to which should we be directed ', LAST_VISITED_SETTINGS_PATH); + if (LAST_VISITED_SETTINGS_PATH !== null) { + Navigation.navigate(LAST_VISITED_SETTINGS_PATH); + return; + } const rootState = navigationRef.getRootState(); const topmostFullScreenRoute = rootState.routes.findLast((route) => isFullScreenName(route.name)); diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 6b7a9cbd13b93..90cd7a317bb5d 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -1,5 +1,5 @@ import type {NavigationState} from '@react-navigation/native'; -import {DarkTheme, DefaultTheme, findFocusedRoute, NavigationContainer} from '@react-navigation/native'; +import {CurrentRenderContext, DarkTheme, DefaultTheme, findFocusedRoute, NavigationContainer} from '@react-navigation/native'; import React, {useContext, useEffect, useMemo, useRef} from 'react'; import {useOnyx} from 'react-native-onyx'; import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider'; @@ -45,6 +45,13 @@ type NavigationRootProps = { onReady: () => void; }; +/** + * Save currentUrl to sessionStorage + */ +function savePathToSessionStorage(path: string) { + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, path); +} + /** * Intercept navigation state changes and log it */ @@ -54,7 +61,6 @@ function parseAndLogRoute(state: NavigationState) { } const currentPath = customGetPathFromState(state, linkingConfig.config); - const focusedRoute = findFocusedRoute(state); if (focusedRoute && !CONST.EXCLUDE_FROM_LAST_VISITED_PATH.includes(focusedRoute?.name)) { @@ -73,6 +79,11 @@ function parseAndLogRoute(state: NavigationState) { Navigation.setIsNavigationReady(); + if (currentPath.includes('/settings')) { + console.log('currentPath', currentPath); + savePathToSessionStorage(currentPath); + } + // Fullstory Page navigation tracking const focusedRouteName = focusedRoute?.name; if (focusedRouteName) { @@ -217,6 +228,8 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N // We want to clean saved scroll offsets for screens that aren't anymore in the state. cleanStaleScrollOffsets(state); cleanPreservedNavigatorStates(state); + + // console.log('state', state); }; return ( From d8676c75cd71baf9f5b442325722d7ca62070965 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 25 Mar 2025 15:55:21 +0100 Subject: [PATCH 02/12] many console logs later --- src/CONST.ts | 3 +- .../Navigation/BottomTabBar/index.tsx | 51 +++++++++++++++---- src/libs/Navigation/NavigationRoot.tsx | 8 +-- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 8ffffbe573b4c..30f5a732819a0 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6312,7 +6312,8 @@ const CONST = { ACTIVE_WORKSPACE_ID: 'ACTIVE_WORKSPACE_ID', RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', - LAST_VISITED_SETTINGS_PATH: 'LAST_VISITED_SETTINGS_PATH' + LAST_VISITED_SETTINGS_PATH: 'LAST_VISITED_SETTINGS_PATH', + LAST_VISITED_SETTINGS_KEY: 'LAST_VISITED_SETTINGS_KEY' }, RESERVATION_TYPE: { diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index c5d0569b01d38..086c9948c4989 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -19,6 +19,7 @@ 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 getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; @@ -115,14 +116,14 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps */ const showSettingsPage = useCallback(() => { const LAST_VISITED_SETTINGS_PATH = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH) as Route | null; - console.log('path to which should we be directed ', LAST_VISITED_SETTINGS_PATH); - if (LAST_VISITED_SETTINGS_PATH !== null) { - Navigation.navigate(LAST_VISITED_SETTINGS_PATH); - return; - } + const LAST_VISITED_SETTINGS_PATH_KEY = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_KEY); + // if (LAST_VISITED_SETTINGS_PATH !== null) { + // Navigation.navigate(LAST_VISITED_SETTINGS_PATH); + // return; + // } const rootState = navigationRef.getRootState(); const topmostFullScreenRoute = rootState.routes.findLast((route) => isFullScreenName(route.name)); - + console.log(topmostFullScreenRoute); if (!topmostFullScreenRoute) { return; } @@ -140,24 +141,49 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps } interceptAnonymousUser(() => { - const lastSettingsOrWorkspaceNavigatorRoute = rootState.routes.findLast( + let settingsState = null; + let settingsStateKey = null; + if (LAST_VISITED_SETTINGS_PATH !== null) { + settingsState = getStateFromPath(LAST_VISITED_SETTINGS_PATH); + settingsStateKey = LAST_VISITED_SETTINGS_PATH_KEY; + settingsState.key = settingsStateKey; + } + const lastSettingsOrWorkspaceNavigatorRoute = settingsState + ? settingsState.routes.findLast((settingsRoute) => settingsRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || settingsRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) + : rootState.routes.findLast((rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR); + const settingsStateNavigationRoute = settingsState + ? settingsState.routes.findLast((settingsRoute) => settingsRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || settingsRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) + : undefined; + const rootStateNavigatorRoute = rootState.routes.findLast( (rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, ); - // If there is no settings or workspace navigator route, then we should open the settings navigator. if (!lastSettingsOrWorkspaceNavigatorRoute) { + console.log('gotcha!'); Navigation.navigate(ROUTES.SETTINGS); return; } - + console.log('is lastSettings settingsState', lastSettingsOrWorkspaceNavigatorRoute === settingsState?.routes.at(-1)); + console.log('settingsState', settingsState); + console.log('settingsStateNavigationRoute', settingsStateNavigationRoute); + console.log('getPreservedNavigatorState(settingsState?.key)', getPreservedNavigatorState(settingsState?.key)); + console.log('rootState', rootState); + console.log('rootStateNavigatorRoute', rootStateNavigatorRoute); + console.log('getPreservedNavigatorState(rootState.key)', getPreservedNavigatorState(rootState.key)); + console.log('|-----------------------------------------------------------------------------------------------------------------------|'); const state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key); - + console.log(state === lastSettingsOrWorkspaceNavigatorRoute.state); + console.log(state); + console.log('lastSettingsOrWorkspaceNavigatorRoute', lastSettingsOrWorkspaceNavigatorRoute); + console.log(''); // If there is a workspace navigator route, then we should open the workspace initial screen as it should be "remembered". if (lastSettingsOrWorkspaceNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { + console.log('last navigator is workspace'); const params = state?.routes.at(0)?.params as WorkspaceSplitNavigatorParamList[typeof SCREENS.WORKSPACE.INITIAL]; - + console.log(params); // Screens of this navigator should always have policyID if (params.policyID) { + console.log('params,policyID', params.policyID); // This action will put settings split under the workspace split to make sure that we can swipe back to settings split. navigationRef.dispatch({ type: CONST.NAVIGATION.ACTION_TYPE.OPEN_WORKSPACE_SPLIT, @@ -165,18 +191,21 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps policyID: params.policyID, }, }); + console.log('after dispatch'); } return; } // If there is settings workspace screen in the settings navigator, then we should open the settings workspaces as it should be "remembered". if (state?.routes?.at(-1)?.name === SCREENS.SETTINGS.WORKSPACES) { + console.log('second if'); Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route); return; } // Otherwise we should simply open the settings navigator. Navigation.navigate(ROUTES.SETTINGS); + console.log('|-----------------------------------------------------------------------------------------------------------------------|'); }); }, [shouldUseNarrowLayout]); diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 90cd7a317bb5d..4851bf2cf2c59 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -1,5 +1,5 @@ -import type {NavigationState} from '@react-navigation/native'; import {CurrentRenderContext, DarkTheme, DefaultTheme, findFocusedRoute, NavigationContainer} from '@react-navigation/native'; +import type {NavigationState} from '@react-navigation/native'; import React, {useContext, useEffect, useMemo, useRef} from 'react'; import {useOnyx} from 'react-native-onyx'; import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider'; @@ -79,9 +79,11 @@ function parseAndLogRoute(state: NavigationState) { Navigation.setIsNavigationReady(); - if (currentPath.includes('/settings')) { - console.log('currentPath', currentPath); + if (state.routes.at(-1)?.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || state.routes.at(-1)?.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { savePathToSessionStorage(currentPath); + if (state.routes.at(-1)) { + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_KEY, state.routes.at(-1)?.key); + } } // Fullstory Page navigation tracking From a345de3e143f6fc11ef1149b2c73406e97654411 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Fri, 28 Mar 2025 17:17:00 +0100 Subject: [PATCH 03/12] poc done and tested --- .../Navigation/BottomTabBar/index.tsx | 55 ++++--------------- .../GetStateForActionHandlers.ts | 7 +-- src/libs/Navigation/NavigationRoot.tsx | 15 +---- .../getLastVisitedWorkspace/index.native.ts | 16 ++++++ .../helpers/getLastVisitedWorkspace/index.ts | 51 +++++++++++++++++ 5 files changed, 84 insertions(+), 60 deletions(-) create mode 100644 src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts create mode 100644 src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 086c9948c4989..00f816ddf79fa 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -16,10 +16,11 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import clearSelectedText from '@libs/clearSelectedText/clearSelectedText'; +import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import getPlatform from '@libs/getPlatform'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import {getPreservedNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState'; -import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; +import {getLastVisitedSettingsPath} from '@libs/Navigation/helpers/getLastVisitedWorkspace/index.native'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; @@ -33,7 +34,8 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES, {Route} from '@src/ROUTES'; +import type {Route} from '@src/ROUTES'; +import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import BOTTOM_TABS from './BOTTOM_TABS'; @@ -115,15 +117,8 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps * If the user clicks on the settings tab while on this tab, this button should go back to the previous screen within the tab. */ const showSettingsPage = useCallback(() => { - const LAST_VISITED_SETTINGS_PATH = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH) as Route | null; - const LAST_VISITED_SETTINGS_PATH_KEY = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_KEY); - // if (LAST_VISITED_SETTINGS_PATH !== null) { - // Navigation.navigate(LAST_VISITED_SETTINGS_PATH); - // return; - // } const rootState = navigationRef.getRootState(); const topmostFullScreenRoute = rootState.routes.findLast((route) => isFullScreenName(route.name)); - console.log(topmostFullScreenRoute); if (!topmostFullScreenRoute) { return; } @@ -141,49 +136,20 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps } interceptAnonymousUser(() => { - let settingsState = null; - let settingsStateKey = null; - if (LAST_VISITED_SETTINGS_PATH !== null) { - settingsState = getStateFromPath(LAST_VISITED_SETTINGS_PATH); - settingsStateKey = LAST_VISITED_SETTINGS_PATH_KEY; - settingsState.key = settingsStateKey; - } - const lastSettingsOrWorkspaceNavigatorRoute = settingsState - ? settingsState.routes.findLast((settingsRoute) => settingsRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || settingsRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) - : rootState.routes.findLast((rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR); - const settingsStateNavigationRoute = settingsState - ? settingsState.routes.findLast((settingsRoute) => settingsRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || settingsRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) - : undefined; - const rootStateNavigatorRoute = rootState.routes.findLast( + const lastSettingsOrWorkspaceNavigatorRoute = rootState.routes.findLast( (rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, ); // If there is no settings or workspace navigator route, then we should open the settings navigator. if (!lastSettingsOrWorkspaceNavigatorRoute) { - console.log('gotcha!'); Navigation.navigate(ROUTES.SETTINGS); return; } - console.log('is lastSettings settingsState', lastSettingsOrWorkspaceNavigatorRoute === settingsState?.routes.at(-1)); - console.log('settingsState', settingsState); - console.log('settingsStateNavigationRoute', settingsStateNavigationRoute); - console.log('getPreservedNavigatorState(settingsState?.key)', getPreservedNavigatorState(settingsState?.key)); - console.log('rootState', rootState); - console.log('rootStateNavigatorRoute', rootStateNavigatorRoute); - console.log('getPreservedNavigatorState(rootState.key)', getPreservedNavigatorState(rootState.key)); - console.log('|-----------------------------------------------------------------------------------------------------------------------|'); const state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key); - console.log(state === lastSettingsOrWorkspaceNavigatorRoute.state); - console.log(state); - console.log('lastSettingsOrWorkspaceNavigatorRoute', lastSettingsOrWorkspaceNavigatorRoute); - console.log(''); // If there is a workspace navigator route, then we should open the workspace initial screen as it should be "remembered". if (lastSettingsOrWorkspaceNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { - console.log('last navigator is workspace'); const params = state?.routes.at(0)?.params as WorkspaceSplitNavigatorParamList[typeof SCREENS.WORKSPACE.INITIAL]; - console.log(params); // Screens of this navigator should always have policyID if (params.policyID) { - console.log('params,policyID', params.policyID); // This action will put settings split under the workspace split to make sure that we can swipe back to settings split. navigationRef.dispatch({ type: CONST.NAVIGATION.ACTION_TYPE.OPEN_WORKSPACE_SPLIT, @@ -191,21 +157,24 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps policyID: params.policyID, }, }); - console.log('after dispatch'); } return; } - + // mamy sciezke zapisana do settings splita (1szego navigatora) + // po prostu navigate mozemy bo tylko jeden split + const lastVisitedSettingsPath = getLastVisitedSettingsPath(); + if (lastVisitedSettingsPath !== '' && !getIsNarrowLayout()) { + Navigation.navigate(lastVisitedSettingsPath as Route); + return; + } // If there is settings workspace screen in the settings navigator, then we should open the settings workspaces as it should be "remembered". if (state?.routes?.at(-1)?.name === SCREENS.SETTINGS.WORKSPACES) { - console.log('second if'); Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route); return; } // Otherwise we should simply open the settings navigator. Navigation.navigate(ROUTES.SETTINGS); - console.log('|-----------------------------------------------------------------------------------------------------------------------|'); }); }, [shouldUseNarrowLayout]); diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts index 658332d99294d..7cfb11b8ef76e 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts @@ -10,6 +10,7 @@ import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; +import getLastVisitedWorkspaceScreen from '@libs/Navigation/helpers/getLastVisitedWorkspace'; import type {OpenWorkspaceSplitActionType, PushActionType, ReplaceActionType, SwitchPolicyIdActionType} from './types'; const MODAL_ROUTES_TO_DISMISS: string[] = [ @@ -50,11 +51,10 @@ function handleOpenWorkspaceSplitAction( stackRouter: Router, CommonActions.Action | StackActionType>, ) { const actionToPushSettingsSplitNavigator = StackActions.push(NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, { - screen: SCREENS.SETTINGS.WORKSPACES, - }); + screen: SCREENS.SETTINGS.WORKSPACES,}); const actionToPushWorkspaceSplitNavigator = StackActions.push(NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, { - screen: SCREENS.WORKSPACE.INITIAL, + screen: getLastVisitedWorkspaceScreen(), params: { policyID: action.payload.policyID, }, @@ -82,7 +82,6 @@ function handleOpenWorkspaceSplitAction( // To make it feel like bottom tab navigator. workspaceSplitsWithoutEnteringAnimation.add(lastFullScreenRoute.key); } - return stateWithWorkspaceSplitNavigator; } diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 4851bf2cf2c59..58fb861d78e97 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -1,4 +1,4 @@ -import {CurrentRenderContext, DarkTheme, DefaultTheme, findFocusedRoute, NavigationContainer} from '@react-navigation/native'; +import {DarkTheme, DefaultTheme, findFocusedRoute, NavigationContainer} from '@react-navigation/native'; import type {NavigationState} from '@react-navigation/native'; import React, {useContext, useEffect, useMemo, useRef} from 'react'; import {useOnyx} from 'react-native-onyx'; @@ -28,6 +28,7 @@ import AppNavigator from './AppNavigator'; import {cleanPreservedNavigatorStates} from './AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import customGetPathFromState from './helpers/customGetPathFromState'; import getAdaptedStateFromPath from './helpers/getAdaptedStateFromPath'; +import {savePathToSessionStorage} from './helpers/getLastVisitedWorkspace'; import {linkingConfig} from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; @@ -45,13 +46,6 @@ type NavigationRootProps = { onReady: () => void; }; -/** - * Save currentUrl to sessionStorage - */ -function savePathToSessionStorage(path: string) { - sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, path); -} - /** * Intercept navigation state changes and log it */ @@ -81,9 +75,6 @@ function parseAndLogRoute(state: NavigationState) { if (state.routes.at(-1)?.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || state.routes.at(-1)?.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { savePathToSessionStorage(currentPath); - if (state.routes.at(-1)) { - sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_KEY, state.routes.at(-1)?.key); - } } // Fullstory Page navigation tracking @@ -230,8 +221,6 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N // We want to clean saved scroll offsets for screens that aren't anymore in the state. cleanStaleScrollOffsets(state); cleanPreservedNavigatorStates(state); - - // console.log('state', state); }; return ( diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts new file mode 100644 index 0000000000000..ebdca1298c197 --- /dev/null +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -0,0 +1,16 @@ +import SCREENS from "@src/SCREENS"; + + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function savePathToSessionStorage(url:string) { +} + +function getLastVisitedWorkspaceScreen() { + return SCREENS.WORKSPACE.INITIAL; +} + +function getLastVisitedSettingsPath() : string { + return ''; +} + +export {savePathToSessionStorage, getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath}; diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts new file mode 100644 index 0000000000000..f5f4d4c2f2616 --- /dev/null +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -0,0 +1,51 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import SCREENS from "@src/SCREENS"; +import CONST from '@src/CONST'; +import getIsNarrowLayout from "@libs/getIsNarrowLayout"; + + +const workspaceScreenNames : Record = { + 'default': SCREENS.WORKSPACE.INITIAL, + 'overview': SCREENS.WORKSPACE.PROFILE, + 'members': SCREENS.WORKSPACE.MEMBERS, + 'distance-rates': SCREENS.WORKSPACE.DISTANCE_RATES, + 'expensify-card': SCREENS.WORKSPACE.EXPENSIFY_CARD, + 'company-cards': SCREENS.WORKSPACE.COMPANY_CARDS, + 'per-diem': SCREENS.WORKSPACE.PER_DIEM, + 'workflows': SCREENS.WORKSPACE.WORKFLOWS, + 'rules': SCREENS.WORKSPACE.RULES, + 'invoices': SCREENS.WORKSPACE.INVOICES, + 'categories': SCREENS.WORKSPACE.CATEGORIES, + 'tags': SCREENS.WORKSPACE.TAGS, + 'taxes': SCREENS.WORKSPACE.TAXES, + 'reportFields': SCREENS.WORKSPACE.REPORT_FIELDS, + 'accounting': SCREENS.WORKSPACE.ACCOUNTING.ROOT, + 'more-features': SCREENS.WORKSPACE.MORE_FEATURES +}; + +function savePathToSessionStorage(url:string) { + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, url); +} + +function getWorkspaceScreenNameKey(url:string) : string{ + const parts = url.split('/'); + return parts.filter(Boolean).pop() ?? ''; +} + +function getLastVisitedSettingsPath() : string { + const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); + return lastVisitedSettingsPath ?? ''; +} + +function getWorkspaceScreenName(key:string) : string{ + return workspaceScreenNames[key] ?? ''; +} + +function getLastVisitedWorkspaceScreen() { + const lastVisitedSettingsPath = getLastVisitedSettingsPath(); + const key = getWorkspaceScreenNameKey(lastVisitedSettingsPath); + const workspaceScreenName = getWorkspaceScreenName(key); + return !getIsNarrowLayout() && workspaceScreenName ? workspaceScreenName : SCREENS.WORKSPACE.INITIAL; +} + +export { getLastVisitedWorkspaceScreen, savePathToSessionStorage, getLastVisitedSettingsPath}; From 7f01c29956f3808c0eb656abfbc8d9d6fd7dd692 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Mon, 31 Mar 2025 10:53:14 +0200 Subject: [PATCH 04/12] navigation to last settings works again --- src/components/Navigation/BottomTabBar/index.tsx | 14 ++++++++------ .../GetStateForActionHandlers.ts | 2 +- .../getLastVisitedWorkspace/index.native.ts | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 00f816ddf79fa..a8429148f9db9 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -20,7 +20,8 @@ import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import getPlatform from '@libs/getPlatform'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import {getPreservedNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState'; -import {getLastVisitedSettingsPath} from '@libs/Navigation/helpers/getLastVisitedWorkspace/index.native'; +import {getLastVisitedSettingsPath} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; +import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; @@ -136,15 +137,17 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps } interceptAnonymousUser(() => { - const lastSettingsOrWorkspaceNavigatorRoute = rootState.routes.findLast( - (rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, - ); + const lastVisitedSettingsPath = getLastVisitedSettingsPath(); + const settingsState = getStateFromPath(lastVisitedSettingsPath as Route); + const lastSettingsOrWorkspaceNavigatorRoute = settingsState + ? settingsState.routes.findLast((settingsRoute) => settingsRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || settingsRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) + : rootState.routes.findLast((rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR); // If there is no settings or workspace navigator route, then we should open the settings navigator. if (!lastSettingsOrWorkspaceNavigatorRoute) { Navigation.navigate(ROUTES.SETTINGS); return; } - const state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key); + const state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key ?? ''); // given so that eslint doesn't throw errors // If there is a workspace navigator route, then we should open the workspace initial screen as it should be "remembered". if (lastSettingsOrWorkspaceNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { const params = state?.routes.at(0)?.params as WorkspaceSplitNavigatorParamList[typeof SCREENS.WORKSPACE.INITIAL]; @@ -162,7 +165,6 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps } // mamy sciezke zapisana do settings splita (1szego navigatora) // po prostu navigate mozemy bo tylko jeden split - const lastVisitedSettingsPath = getLastVisitedSettingsPath(); if (lastVisitedSettingsPath !== '' && !getIsNarrowLayout()) { Navigation.navigate(lastVisitedSettingsPath as Route); return; diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts index 7cfb11b8ef76e..7c9365c2aca87 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts @@ -10,7 +10,7 @@ import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; -import getLastVisitedWorkspaceScreen from '@libs/Navigation/helpers/getLastVisitedWorkspace'; +import {getLastVisitedWorkspaceScreen} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; import type {OpenWorkspaceSplitActionType, PushActionType, ReplaceActionType, SwitchPolicyIdActionType} from './types'; const MODAL_ROUTES_TO_DISMISS: string[] = [ diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts index ebdca1298c197..9d25b2ac4a8a0 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -9,7 +9,7 @@ function getLastVisitedWorkspaceScreen() { return SCREENS.WORKSPACE.INITIAL; } -function getLastVisitedSettingsPath() : string { +function getLastVisitedSettingsPath() : string { return ''; } From d510c0eb44ac4585b904f3cfa66b49f014ba4575 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Mon, 31 Mar 2025 10:59:14 +0200 Subject: [PATCH 05/12] npm run prettier --- src/CONST.ts | 2 +- .../GetStateForActionHandlers.ts | 5 ++- .../getLastVisitedWorkspace/index.native.ts | 10 ++--- .../helpers/getLastVisitedWorkspace/index.ts | 43 +++++++++---------- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 30f5a732819a0..3930082455b22 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6313,7 +6313,7 @@ const CONST = { RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', LAST_VISITED_SETTINGS_PATH: 'LAST_VISITED_SETTINGS_PATH', - LAST_VISITED_SETTINGS_KEY: 'LAST_VISITED_SETTINGS_KEY' + LAST_VISITED_SETTINGS_KEY: 'LAST_VISITED_SETTINGS_KEY', }, RESERVATION_TYPE: { diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts index 7c9365c2aca87..5c096654fbd76 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts @@ -4,13 +4,13 @@ import type {ParamListBase, Router} from '@react-navigation/routers'; import Onyx from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import Log from '@libs/Log'; +import {getLastVisitedWorkspaceScreen} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; import getPolicyIDFromState from '@libs/Navigation/helpers/getPolicyIDFromState'; import type {RootNavigatorParamList, State} from '@libs/Navigation/types'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; -import {getLastVisitedWorkspaceScreen} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; import type {OpenWorkspaceSplitActionType, PushActionType, ReplaceActionType, SwitchPolicyIdActionType} from './types'; const MODAL_ROUTES_TO_DISMISS: string[] = [ @@ -51,7 +51,8 @@ function handleOpenWorkspaceSplitAction( stackRouter: Router, CommonActions.Action | StackActionType>, ) { const actionToPushSettingsSplitNavigator = StackActions.push(NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, { - screen: SCREENS.SETTINGS.WORKSPACES,}); + screen: SCREENS.SETTINGS.WORKSPACES, + }); const actionToPushWorkspaceSplitNavigator = StackActions.push(NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, { screen: getLastVisitedWorkspaceScreen(), diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts index 9d25b2ac4a8a0..d31a144bf31bf 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -1,16 +1,14 @@ -import SCREENS from "@src/SCREENS"; - +import SCREENS from '@src/SCREENS'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -function savePathToSessionStorage(url:string) { -} +function savePathToSessionStorage(url: string) {} function getLastVisitedWorkspaceScreen() { return SCREENS.WORKSPACE.INITIAL; } -function getLastVisitedSettingsPath() : string { +function getLastVisitedSettingsPath(): string { return ''; } -export {savePathToSessionStorage, getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath}; +export {savePathToSessionStorage, getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath}; diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts index f5f4d4c2f2616..401ad29981616 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -1,43 +1,42 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import SCREENS from "@src/SCREENS"; +import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import CONST from '@src/CONST'; -import getIsNarrowLayout from "@libs/getIsNarrowLayout"; +import SCREENS from '@src/SCREENS'; - -const workspaceScreenNames : Record = { - 'default': SCREENS.WORKSPACE.INITIAL, - 'overview': SCREENS.WORKSPACE.PROFILE, - 'members': SCREENS.WORKSPACE.MEMBERS, +const workspaceScreenNames: Record = { + default: SCREENS.WORKSPACE.INITIAL, + overview: SCREENS.WORKSPACE.PROFILE, + members: SCREENS.WORKSPACE.MEMBERS, 'distance-rates': SCREENS.WORKSPACE.DISTANCE_RATES, 'expensify-card': SCREENS.WORKSPACE.EXPENSIFY_CARD, 'company-cards': SCREENS.WORKSPACE.COMPANY_CARDS, 'per-diem': SCREENS.WORKSPACE.PER_DIEM, - 'workflows': SCREENS.WORKSPACE.WORKFLOWS, - 'rules': SCREENS.WORKSPACE.RULES, - 'invoices': SCREENS.WORKSPACE.INVOICES, - 'categories': SCREENS.WORKSPACE.CATEGORIES, - 'tags': SCREENS.WORKSPACE.TAGS, - 'taxes': SCREENS.WORKSPACE.TAXES, - 'reportFields': SCREENS.WORKSPACE.REPORT_FIELDS, - 'accounting': SCREENS.WORKSPACE.ACCOUNTING.ROOT, - 'more-features': SCREENS.WORKSPACE.MORE_FEATURES + workflows: SCREENS.WORKSPACE.WORKFLOWS, + rules: SCREENS.WORKSPACE.RULES, + invoices: SCREENS.WORKSPACE.INVOICES, + categories: SCREENS.WORKSPACE.CATEGORIES, + tags: SCREENS.WORKSPACE.TAGS, + taxes: SCREENS.WORKSPACE.TAXES, + reportFields: SCREENS.WORKSPACE.REPORT_FIELDS, + accounting: SCREENS.WORKSPACE.ACCOUNTING.ROOT, + 'more-features': SCREENS.WORKSPACE.MORE_FEATURES, }; -function savePathToSessionStorage(url:string) { +function savePathToSessionStorage(url: string) { sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, url); } -function getWorkspaceScreenNameKey(url:string) : string{ +function getWorkspaceScreenNameKey(url: string): string { const parts = url.split('/'); return parts.filter(Boolean).pop() ?? ''; } -function getLastVisitedSettingsPath() : string { +function getLastVisitedSettingsPath(): string { const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); return lastVisitedSettingsPath ?? ''; } -function getWorkspaceScreenName(key:string) : string{ +function getWorkspaceScreenName(key: string): string { return workspaceScreenNames[key] ?? ''; } @@ -45,7 +44,7 @@ function getLastVisitedWorkspaceScreen() { const lastVisitedSettingsPath = getLastVisitedSettingsPath(); const key = getWorkspaceScreenNameKey(lastVisitedSettingsPath); const workspaceScreenName = getWorkspaceScreenName(key); - return !getIsNarrowLayout() && workspaceScreenName ? workspaceScreenName : SCREENS.WORKSPACE.INITIAL; + return !getIsNarrowLayout() && workspaceScreenName ? workspaceScreenName : SCREENS.WORKSPACE.INITIAL; } -export { getLastVisitedWorkspaceScreen, savePathToSessionStorage, getLastVisitedSettingsPath}; +export {getLastVisitedWorkspaceScreen, savePathToSessionStorage, getLastVisitedSettingsPath}; From 736869679b2693b8df8cb9f262cfa438ffaff218 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 1 Apr 2025 15:43:20 +0200 Subject: [PATCH 06/12] removed unused vars, changed comments to english --- src/CONST.ts | 1 - src/components/Navigation/BottomTabBar/index.tsx | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 3930082455b22..05e4eca6e8394 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6313,7 +6313,6 @@ const CONST = { RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', LAST_VISITED_SETTINGS_PATH: 'LAST_VISITED_SETTINGS_PATH', - LAST_VISITED_SETTINGS_KEY: 'LAST_VISITED_SETTINGS_KEY', }, RESERVATION_TYPE: { diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index a8429148f9db9..3a752ca53a3c1 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -163,8 +163,7 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps } return; } - // mamy sciezke zapisana do settings splita (1szego navigatora) - // po prostu navigate mozemy bo tylko jeden split + // if we have saved path to settings we navigate to it if (lastVisitedSettingsPath !== '' && !getIsNarrowLayout()) { Navigation.navigate(lastVisitedSettingsPath as Route); return; From b6c9bba0a05e1e4fc801f08f8362bfa7fada7c33 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Wed, 2 Apr 2025 16:18:25 +0200 Subject: [PATCH 07/12] changed sigantrue of methods, refactor, removed unused record --- .../Navigation/BottomTabBar/index.tsx | 39 ++++++++----- .../GetStateForActionHandlers.ts | 3 +- src/libs/Navigation/NavigationRoot.tsx | 5 +- .../getLastVisitedWorkspace/index.native.ts | 19 +++++-- .../helpers/getLastVisitedWorkspace/index.ts | 55 +++++++------------ 5 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 3a752ca53a3c1..341a81abb64ae 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -16,12 +16,10 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import clearSelectedText from '@libs/clearSelectedText/clearSelectedText'; -import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import getPlatform from '@libs/getPlatform'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import {getPreservedNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState'; -import {getLastVisitedSettingsPath} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; -import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; +import {getLastVisitedSettingsPath, getLastVisitedWorkspaceScreen, getSettingsTabStateFromSessionStorage} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; @@ -35,7 +33,6 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import BOTTOM_TABS from './BOTTOM_TABS'; @@ -137,39 +134,51 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps } interceptAnonymousUser(() => { - const lastVisitedSettingsPath = getLastVisitedSettingsPath(); - const settingsState = getStateFromPath(lastVisitedSettingsPath as Route); - const lastSettingsOrWorkspaceNavigatorRoute = settingsState - ? settingsState.routes.findLast((settingsRoute) => settingsRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || settingsRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) - : rootState.routes.findLast((rootRoute) => rootRoute.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || rootRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR); + const state = getSettingsTabStateFromSessionStorage() ?? rootState; + const lastSettingsOrWorkspaceNavigatorRoute = state.routes.findLast( + (route) => route.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || route.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, + ); // If there is no settings or workspace navigator route, then we should open the settings navigator. if (!lastSettingsOrWorkspaceNavigatorRoute) { Navigation.navigate(ROUTES.SETTINGS); return; } - const state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key ?? ''); // given so that eslint doesn't throw errors + + // might comment later + let settingsTabState = lastSettingsOrWorkspaceNavigatorRoute.state; + if (!settingsTabState && lastSettingsOrWorkspaceNavigatorRoute.key) { + settingsTabState = getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key); + } + + // state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key ?? ''); // given so that eslint doesn't throw errors // If there is a workspace navigator route, then we should open the workspace initial screen as it should be "remembered". if (lastSettingsOrWorkspaceNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { - const params = state?.routes.at(0)?.params as WorkspaceSplitNavigatorParamList[typeof SCREENS.WORKSPACE.INITIAL]; + const params = settingsTabState?.routes.at(0)?.params as WorkspaceSplitNavigatorParamList[typeof SCREENS.WORKSPACE.INITIAL]; // Screens of this navigator should always have policyID if (params.policyID) { + const workspaceScreenName = !shouldUseNarrowLayout ? getLastVisitedWorkspaceScreen() : SCREENS.WORKSPACE.INITIAL; // This action will put settings split under the workspace split to make sure that we can swipe back to settings split. navigationRef.dispatch({ type: CONST.NAVIGATION.ACTION_TYPE.OPEN_WORKSPACE_SPLIT, payload: { policyID: params.policyID, + screenName: workspaceScreenName, }, }); } return; } - // if we have saved path to settings we navigate to it - if (lastVisitedSettingsPath !== '' && !getIsNarrowLayout()) { - Navigation.navigate(lastVisitedSettingsPath as Route); + + // If we have saved path and we don't navigate to workspace screen and we are on widescreen we just navigate to this url + if (settingsTabState && !shouldUseNarrowLayout) { + const lastVisitedSettingsRoute = getLastVisitedSettingsPath(settingsTabState); + if (lastVisitedSettingsRoute) { + Navigation.navigate(lastVisitedSettingsRoute); + } return; } // If there is settings workspace screen in the settings navigator, then we should open the settings workspaces as it should be "remembered". - if (state?.routes?.at(-1)?.name === SCREENS.SETTINGS.WORKSPACES) { + if (settingsTabState?.routes?.at(-1)?.name === SCREENS.SETTINGS.WORKSPACES) { Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route); return; } diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts index 5c096654fbd76..b72d47f8ea124 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts @@ -55,7 +55,7 @@ function handleOpenWorkspaceSplitAction( }); const actionToPushWorkspaceSplitNavigator = StackActions.push(NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, { - screen: getLastVisitedWorkspaceScreen(), + screen: getLastVisitedWorkspaceScreen(), // add a comment explaining what it does params: { policyID: action.payload.policyID, }, @@ -83,6 +83,7 @@ function handleOpenWorkspaceSplitAction( // To make it feel like bottom tab navigator. workspaceSplitsWithoutEnteringAnimation.add(lastFullScreenRoute.key); } + return stateWithWorkspaceSplitNavigator; } diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 58fb861d78e97..eb54aac935591 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -28,7 +28,7 @@ import AppNavigator from './AppNavigator'; import {cleanPreservedNavigatorStates} from './AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import customGetPathFromState from './helpers/customGetPathFromState'; import getAdaptedStateFromPath from './helpers/getAdaptedStateFromPath'; -import {savePathToSessionStorage} from './helpers/getLastVisitedWorkspace'; +import {saveSettingsStatePathToSessionStorage} from './helpers/getLastVisitedWorkspace'; import {linkingConfig} from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; @@ -55,6 +55,7 @@ function parseAndLogRoute(state: NavigationState) { } const currentPath = customGetPathFromState(state, linkingConfig.config); + const focusedRoute = findFocusedRoute(state); if (focusedRoute && !CONST.EXCLUDE_FROM_LAST_VISITED_PATH.includes(focusedRoute?.name)) { @@ -74,7 +75,7 @@ function parseAndLogRoute(state: NavigationState) { Navigation.setIsNavigationReady(); if (state.routes.at(-1)?.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || state.routes.at(-1)?.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { - savePathToSessionStorage(currentPath); + saveSettingsStatePathToSessionStorage(currentPath); } // Fullstory Page navigation tracking diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts index d31a144bf31bf..5cb81ef16dfac 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -1,14 +1,21 @@ +import type { NavigationState, PartialState } from '@react-navigation/native'; +import type { Route } from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -function savePathToSessionStorage(url: string) {} +function saveSettingsStatePathToSessionStorage(url: string) {} -function getLastVisitedWorkspaceScreen() { - return SCREENS.WORKSPACE.INITIAL; +function getSettingsTabStateFromSessionStorage(): PartialState | undefined{ + return undefined; } -function getLastVisitedSettingsPath(): string { - return ''; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getLastVisitedSettingsPath(state?: PartialState): Route | undefined { + return undefined; +} + +function getLastVisitedWorkspaceScreen() { + return SCREENS.WORKSPACE.INITIAL; } -export {savePathToSessionStorage, getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath}; +export {getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath, saveSettingsStatePathToSessionStorage, getSettingsTabStateFromSessionStorage}; diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts index 401ad29981616..dae4a9d99a5b1 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -1,50 +1,37 @@ +import type { NavigationState, PartialState } from '@react-navigation/native'; +import { findFocusedRoute } from '@react-navigation/native'; /* eslint-disable @typescript-eslint/naming-convention */ -import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import CONST from '@src/CONST'; +import type { Route } from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; +import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; -const workspaceScreenNames: Record = { - default: SCREENS.WORKSPACE.INITIAL, - overview: SCREENS.WORKSPACE.PROFILE, - members: SCREENS.WORKSPACE.MEMBERS, - 'distance-rates': SCREENS.WORKSPACE.DISTANCE_RATES, - 'expensify-card': SCREENS.WORKSPACE.EXPENSIFY_CARD, - 'company-cards': SCREENS.WORKSPACE.COMPANY_CARDS, - 'per-diem': SCREENS.WORKSPACE.PER_DIEM, - workflows: SCREENS.WORKSPACE.WORKFLOWS, - rules: SCREENS.WORKSPACE.RULES, - invoices: SCREENS.WORKSPACE.INVOICES, - categories: SCREENS.WORKSPACE.CATEGORIES, - tags: SCREENS.WORKSPACE.TAGS, - taxes: SCREENS.WORKSPACE.TAXES, - reportFields: SCREENS.WORKSPACE.REPORT_FIELDS, - accounting: SCREENS.WORKSPACE.ACCOUNTING.ROOT, - 'more-features': SCREENS.WORKSPACE.MORE_FEATURES, -}; - -function savePathToSessionStorage(url: string) { +function saveSettingsStatePathToSessionStorage(url: string) { sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, url); } -function getWorkspaceScreenNameKey(url: string): string { - const parts = url.split('/'); - return parts.filter(Boolean).pop() ?? ''; -} -function getLastVisitedSettingsPath(): string { +function getSettingsTabStateFromSessionStorage(): PartialState | undefined{ const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); - return lastVisitedSettingsPath ?? ''; + if (!lastVisitedSettingsPath) { + return undefined; + } + return getStateFromPath(lastVisitedSettingsPath as Route); +} + + +function getWorkspaceScreenNameFromState(state?: PartialState) { + return state.routes.at(-1)?.state?.routes.at(-1).name ?? undefined; } -function getWorkspaceScreenName(key: string): string { - return workspaceScreenNames[key] ?? ''; +function getLastVisitedSettingsPath(state?: PartialState | undefined): Route | undefined{ + return state ? findFocusedRoute(state)?.path as Route : undefined; } function getLastVisitedWorkspaceScreen() { - const lastVisitedSettingsPath = getLastVisitedSettingsPath(); - const key = getWorkspaceScreenNameKey(lastVisitedSettingsPath); - const workspaceScreenName = getWorkspaceScreenName(key); - return !getIsNarrowLayout() && workspaceScreenName ? workspaceScreenName : SCREENS.WORKSPACE.INITIAL; + const settingsState = getSettingsTabStateFromSessionStorage(); + const workspaceScreenName = getWorkspaceScreenNameFromState(settingsState); + return workspaceScreenName ?? SCREENS.WORKSPACE.INITIAL; } -export {getLastVisitedWorkspaceScreen, savePathToSessionStorage, getLastVisitedSettingsPath}; +export {getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath, saveSettingsStatePathToSessionStorage, getSettingsTabStateFromSessionStorage}; From d292ac15dae79cfb0efa917a96d73019b5ed9593 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Thu, 3 Apr 2025 15:51:47 +0200 Subject: [PATCH 08/12] added workspacescreenname key, updated function definitions --- .../GetStateForActionHandlers.ts | 3 +-- .../createRootStackNavigator/types.ts | 2 ++ .../getLastVisitedWorkspace/index.native.ts | 8 ++++---- .../helpers/getLastVisitedWorkspace/index.ts | 19 +++++++++---------- src/libs/Navigation/types.ts | 3 +++ 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts index b72d47f8ea124..653ecbcdfdbe8 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts @@ -4,7 +4,6 @@ import type {ParamListBase, Router} from '@react-navigation/routers'; import Onyx from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import Log from '@libs/Log'; -import {getLastVisitedWorkspaceScreen} from '@libs/Navigation/helpers/getLastVisitedWorkspace'; import getPolicyIDFromState from '@libs/Navigation/helpers/getPolicyIDFromState'; import type {RootNavigatorParamList, State} from '@libs/Navigation/types'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; @@ -55,7 +54,7 @@ function handleOpenWorkspaceSplitAction( }); const actionToPushWorkspaceSplitNavigator = StackActions.push(NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, { - screen: getLastVisitedWorkspaceScreen(), // add a comment explaining what it does + screen: action.payload.screenName, params: { policyID: action.payload.policyID, }, diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/types.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/types.ts index 67d69f90a2056..1727c8fa61c6e 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/types.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/types.ts @@ -1,5 +1,6 @@ import type {CommonActions, DefaultNavigatorOptions, ParamListBase, StackActionType, StackNavigationState, StackRouterOptions} from '@react-navigation/native'; import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack'; +import type {WorkspaceScreenName} from '@libs/Navigation/types'; import type CONST from '@src/CONST'; type RootStackNavigatorActionType = @@ -16,6 +17,7 @@ type RootStackNavigatorActionType = type: typeof CONST.NAVIGATION.ACTION_TYPE.OPEN_WORKSPACE_SPLIT; payload: { policyID: string; + screenName: WorkspaceScreenName; }; }; diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts index 5cb81ef16dfac..d3595b5f32b09 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -1,16 +1,16 @@ -import type { NavigationState, PartialState } from '@react-navigation/native'; -import type { Route } from '@src/ROUTES'; +import type {NavigationState, PartialState} from '@react-navigation/native'; +import type {Route} from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; // eslint-disable-next-line @typescript-eslint/no-unused-vars function saveSettingsStatePathToSessionStorage(url: string) {} -function getSettingsTabStateFromSessionStorage(): PartialState | undefined{ +function getSettingsTabStateFromSessionStorage(): PartialState | undefined { return undefined; } // eslint-disable-next-line @typescript-eslint/no-unused-vars -function getLastVisitedSettingsPath(state?: PartialState): Route | undefined { +function getLastVisitedSettingsPath(state?: NavigationState | PartialState | undefined): Route | undefined { return undefined; } diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts index dae4a9d99a5b1..c66bcb19838d0 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -1,17 +1,17 @@ -import type { NavigationState, PartialState } from '@react-navigation/native'; -import { findFocusedRoute } from '@react-navigation/native'; +import type {NavigationState, PartialState} from '@react-navigation/native'; +import {findFocusedRoute} from '@react-navigation/native'; +import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; + /* eslint-disable @typescript-eslint/naming-convention */ import CONST from '@src/CONST'; -import type { Route } from '@src/ROUTES'; +import type {Route} from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; function saveSettingsStatePathToSessionStorage(url: string) { sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, url); } - -function getSettingsTabStateFromSessionStorage(): PartialState | undefined{ +function getSettingsTabStateFromSessionStorage(): PartialState | undefined { const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); if (!lastVisitedSettingsPath) { return undefined; @@ -19,13 +19,12 @@ function getSettingsTabStateFromSessionStorage(): PartialState return getStateFromPath(lastVisitedSettingsPath as Route); } - function getWorkspaceScreenNameFromState(state?: PartialState) { - return state.routes.at(-1)?.state?.routes.at(-1).name ?? undefined; + return state?.routes.at(-1)?.state?.routes.at(-1)?.name ?? undefined; } -function getLastVisitedSettingsPath(state?: PartialState | undefined): Route | undefined{ - return state ? findFocusedRoute(state)?.path as Route : undefined; +function getLastVisitedSettingsPath(state?: NavigationState | PartialState | undefined): Route | undefined { + return state ? (findFocusedRoute(state)?.path as Route) : undefined; } function getLastVisitedWorkspaceScreen() { diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 20313e1aef0cf..74be08d8038fb 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1954,6 +1954,8 @@ type SearchFullscreenNavigatorName = typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGAT type FullScreenName = SplitNavigatorName | SearchFullscreenNavigatorName; +type WorkspaceScreenName = typeof SCREENS.WORKSPACE; + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace ReactNavigation { @@ -2029,4 +2031,5 @@ export type { WorkspaceConfirmationNavigatorParamList, TwoFactorAuthNavigatorParamList, ConsoleNavigatorParamList, + WorkspaceScreenName, }; From ceb1093b2bbd58e56fc75249974ad70603b2d4aa Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 8 Apr 2025 11:53:16 +0200 Subject: [PATCH 09/12] added method to check if screen is from workspace or settings split, refactor --- src/components/Navigation/BottomTabBar/index.tsx | 11 ++++------- src/libs/Navigation/NavigationRoot.tsx | 8 ++++---- .../getLastVisitedWorkspace/index.native.ts | 7 +++---- .../helpers/getLastVisitedWorkspace/index.ts | 14 ++++++-------- src/libs/Navigation/helpers/isNavigatorName.ts | 14 +++++++++++--- src/libs/Navigation/types.ts | 10 +++++++++- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 341a81abb64ae..19cb9c1f4dc20 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -23,7 +23,7 @@ import {getLastVisitedSettingsPath, getLastVisitedWorkspaceScreen, getSettingsTa import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; -import {isFullScreenName} from '@navigation/helpers/isNavigatorName'; +import {isFullScreenName, isSettingsTabScreenName} from '@navigation/helpers/isNavigatorName'; import Navigation from '@navigation/Navigation'; import navigationRef from '@navigation/navigationRef'; import type {RootNavigatorParamList, SearchFullscreenNavigatorParamList, State, WorkspaceSplitNavigatorParamList} from '@navigation/types'; @@ -135,22 +135,18 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps interceptAnonymousUser(() => { const state = getSettingsTabStateFromSessionStorage() ?? rootState; - const lastSettingsOrWorkspaceNavigatorRoute = state.routes.findLast( - (route) => route.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || route.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, - ); + const lastSettingsOrWorkspaceNavigatorRoute = state.routes.findLast((route) => isSettingsTabScreenName(route.name)); // If there is no settings or workspace navigator route, then we should open the settings navigator. if (!lastSettingsOrWorkspaceNavigatorRoute) { Navigation.navigate(ROUTES.SETTINGS); return; } - // might comment later let settingsTabState = lastSettingsOrWorkspaceNavigatorRoute.state; if (!settingsTabState && lastSettingsOrWorkspaceNavigatorRoute.key) { settingsTabState = getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key); } - // state = lastSettingsOrWorkspaceNavigatorRoute.state ?? getPreservedNavigatorState(lastSettingsOrWorkspaceNavigatorRoute.key ?? ''); // given so that eslint doesn't throw errors // If there is a workspace navigator route, then we should open the workspace initial screen as it should be "remembered". if (lastSettingsOrWorkspaceNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { const params = settingsTabState?.routes.at(0)?.params as WorkspaceSplitNavigatorParamList[typeof SCREENS.WORKSPACE.INITIAL]; @@ -169,7 +165,8 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps return; } - // If we have saved path and we don't navigate to workspace screen and we are on widescreen we just navigate to this url + // If the path stored in session 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 (settingsTabState && !shouldUseNarrowLayout) { const lastVisitedSettingsRoute = getLastVisitedSettingsPath(settingsTabState); if (lastVisitedSettingsRoute) { diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index eb54aac935591..edd4a0ba2bd85 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -28,7 +28,8 @@ import AppNavigator from './AppNavigator'; import {cleanPreservedNavigatorStates} from './AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import customGetPathFromState from './helpers/customGetPathFromState'; import getAdaptedStateFromPath from './helpers/getAdaptedStateFromPath'; -import {saveSettingsStatePathToSessionStorage} from './helpers/getLastVisitedWorkspace'; +import {saveSettingsTabPathToSessionStorage} from './helpers/getLastVisitedWorkspace'; +import {isSettingsTabScreenName} from './helpers/isNavigatorName'; import {linkingConfig} from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; @@ -73,9 +74,8 @@ function parseAndLogRoute(state: NavigationState) { } Navigation.setIsNavigationReady(); - - if (state.routes.at(-1)?.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR || state.routes.at(-1)?.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { - saveSettingsStatePathToSessionStorage(currentPath); + if (isSettingsTabScreenName(state.routes.at(-1)?.name)) { + saveSettingsTabPathToSessionStorage(currentPath); } // Fullstory Page navigation tracking diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts index d3595b5f32b09..c442bff9e65f9 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -1,9 +1,8 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; import type {Route} from '@src/ROUTES'; -import SCREENS from '@src/SCREENS'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -function saveSettingsStatePathToSessionStorage(url: string) {} +function saveSettingsTabPathToSessionStorage(url: string) {} function getSettingsTabStateFromSessionStorage(): PartialState | undefined { return undefined; @@ -15,7 +14,7 @@ function getLastVisitedSettingsPath(state?: NavigationState | PartialState | undefined { - const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); + const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH) as Route; if (!lastVisitedSettingsPath) { return undefined; } - return getStateFromPath(lastVisitedSettingsPath as Route); + return getStateFromPath(lastVisitedSettingsPath); } function getWorkspaceScreenNameFromState(state?: PartialState) { - return state?.routes.at(-1)?.state?.routes.at(-1)?.name ?? undefined; + return state?.routes.at(-1)?.state?.routes.at(-1)?.name; } function getLastVisitedSettingsPath(state?: NavigationState | PartialState | undefined): Route | undefined { @@ -30,7 +28,7 @@ function getLastVisitedSettingsPath(state?: NavigationState | PartialState(screen, SIDEBARS_SET); } - -export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName}; +function isSettingsTabScreenName(screen: string | undefined) { + return checkIfScreenHasMatchingNameToSetValues(screen, SETTINGS_NAVIGATOR_SPLIT_SET); +} +export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName, isSettingsTabScreenName}; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 74be08d8038fb..88ab23db3cef4 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -57,6 +57,11 @@ type NavigationRoute = NavigationStateRoute | NavigationPartialRoute; type SplitNavigatorSidebarScreen = keyof typeof SIDEBAR_TO_SPLIT; +type SettingsTabScreenName = { + [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SettingsSplitNavigatorParamList; + [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: WorkspaceSplitNavigatorParamList; +}; + type SplitNavigatorParamList = { [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SettingsSplitNavigatorParamList; [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: ReportsSplitNavigatorParamList; @@ -1954,7 +1959,9 @@ type SearchFullscreenNavigatorName = typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGAT type FullScreenName = SplitNavigatorName | SearchFullscreenNavigatorName; -type WorkspaceScreenName = typeof SCREENS.WORKSPACE; +type SettingsTabScreen = keyof SettingsTabScreenName; + +type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace @@ -2032,4 +2039,5 @@ export type { TwoFactorAuthNavigatorParamList, ConsoleNavigatorParamList, WorkspaceScreenName, + SettingsTabScreen, }; From 29928edc69ed942867f8ff1855c03788b0a3ad0c Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 8 Apr 2025 13:15:26 +0200 Subject: [PATCH 10/12] npm run prettier --- .../Navigation/helpers/getLastVisitedWorkspace/index.ts | 1 - src/libs/Navigation/helpers/isNavigatorName.ts | 6 +++--- src/libs/Navigation/types.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts index ef8d0cc184787..a2d161a430420 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -1,7 +1,6 @@ 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'; diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index 587b8a92915c8..9d1683bf29c9d 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 {SettingsTabScreen, FullScreenName, OnboardingFlowName, SplitNavigatorName, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; +import type {FullScreenName, OnboardingFlowName, SettingsTabScreen, SplitNavigatorName, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; @@ -15,8 +15,8 @@ const ONBOARDING_SCREENS = [ const SETTINGS_TAB = { [SCREENS.SETTINGS.ROOT]: NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, - [SCREENS.WORKSPACE.INITIAL]: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR -} + [SCREENS.WORKSPACE.INITIAL]: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, +}; const FULL_SCREENS_SET = new Set([...Object.values(SIDEBAR_TO_SPLIT), NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR]); const SIDEBARS_SET = new Set(Object.values(SPLIT_TO_SIDEBAR)); diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 88ab23db3cef4..d7f79852a6db9 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1959,7 +1959,7 @@ type SearchFullscreenNavigatorName = typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGAT type FullScreenName = SplitNavigatorName | SearchFullscreenNavigatorName; -type SettingsTabScreen = keyof SettingsTabScreenName; +type SettingsTabScreen = keyof SettingsTabScreenName; type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; From da239f0e5f5167e6720393f3ca8d829e312736ba Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 8 Apr 2025 14:43:44 +0200 Subject: [PATCH 11/12] refactor of added functions, refactor of comments --- src/components/Navigation/BottomTabBar/index.tsx | 4 ++-- .../helpers/getLastVisitedWorkspace/index.native.ts | 2 +- .../helpers/getLastVisitedWorkspace/index.ts | 12 ++++++++---- src/libs/Navigation/helpers/isNavigatorName.ts | 11 +++-------- src/libs/Navigation/types.ts | 9 ++------- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 19cb9c1f4dc20..2112c377182e1 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -165,14 +165,14 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps return; } - // If the path stored in session session storage leads to a settings screen, we just navigate to it on a wide layout. + // 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 (settingsTabState && !shouldUseNarrowLayout) { const lastVisitedSettingsRoute = getLastVisitedSettingsPath(settingsTabState); if (lastVisitedSettingsRoute) { Navigation.navigate(lastVisitedSettingsRoute); + return; } - return; } // If there is settings workspace screen in the settings navigator, then we should open the settings workspaces as it should be "remembered". if (settingsTabState?.routes?.at(-1)?.name === SCREENS.SETTINGS.WORKSPACES) { diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts index c442bff9e65f9..451a35d5bf6c2 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.native.ts @@ -9,7 +9,7 @@ function getSettingsTabStateFromSessionStorage(): PartialState } // eslint-disable-next-line @typescript-eslint/no-unused-vars -function getLastVisitedSettingsPath(state?: NavigationState | PartialState | undefined): Route | undefined { +function getLastVisitedSettingsPath(state: NavigationState | PartialState): Route | undefined { return undefined; } diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts index a2d161a430420..e1312610ff9f2 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -9,19 +9,23 @@ function saveSettingsTabPathToSessionStorage(url: string) { } function getSettingsTabStateFromSessionStorage(): PartialState | undefined { - const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH) as Route; + const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); if (!lastVisitedSettingsPath) { return undefined; } - return getStateFromPath(lastVisitedSettingsPath); + return getStateFromPath(lastVisitedSettingsPath as Route); } function getWorkspaceScreenNameFromState(state?: PartialState) { return state?.routes.at(-1)?.state?.routes.at(-1)?.name; } -function getLastVisitedSettingsPath(state?: NavigationState | PartialState | undefined): Route | undefined { - return state ? (findFocusedRoute(state)?.path as Route) : undefined; +function getLastVisitedSettingsPath(state: NavigationState | PartialState): Route | undefined { + const lastVisitedSettingsPath = findFocusedRoute(state)?.path; + if (!lastVisitedSettingsPath) { + return undefined; + } + return lastVisitedSettingsPath as Route; } function getLastVisitedWorkspaceScreen() { diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index 9d1683bf29c9d..c4e8ec1cac6fb 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, SettingsTabScreen, SplitNavigatorName, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; +import type {FullScreenName, OnboardingFlowName, SettingsTabScreenName, SplitNavigatorName, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; @@ -13,16 +13,11 @@ const ONBOARDING_SCREENS = [ SCREENS.ONBOARDING.WORKSPACES, ]; -const SETTINGS_TAB = { - [SCREENS.SETTINGS.ROOT]: NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, - [SCREENS.WORKSPACE.INITIAL]: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, -}; - const FULL_SCREENS_SET = new Set([...Object.values(SIDEBAR_TO_SPLIT), NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR]); 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 SETTINGS_NAVIGATOR_SPLIT_SET = new Set(Object.values(SETTINGS_TAB)); +const SETTINGS_TAB_SET = new Set(Object.values([NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR])); /** * Functions defined below are used to check whether a screen belongs to a specific group. @@ -52,6 +47,6 @@ function isSidebarScreenName(screen: string | undefined) { return checkIfScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); } function isSettingsTabScreenName(screen: string | undefined) { - return checkIfScreenHasMatchingNameToSetValues(screen, SETTINGS_NAVIGATOR_SPLIT_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, SETTINGS_TAB_SET); } export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName, isSettingsTabScreenName}; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index d7f79852a6db9..c261d5408f096 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -57,11 +57,6 @@ type NavigationRoute = NavigationStateRoute | NavigationPartialRoute; type SplitNavigatorSidebarScreen = keyof typeof SIDEBAR_TO_SPLIT; -type SettingsTabScreenName = { - [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SettingsSplitNavigatorParamList; - [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: WorkspaceSplitNavigatorParamList; -}; - type SplitNavigatorParamList = { [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SettingsSplitNavigatorParamList; [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: ReportsSplitNavigatorParamList; @@ -1959,7 +1954,7 @@ type SearchFullscreenNavigatorName = typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGAT type FullScreenName = SplitNavigatorName | SearchFullscreenNavigatorName; -type SettingsTabScreen = keyof SettingsTabScreenName; +type SettingsTabScreenName = typeof NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR | typeof NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR; type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; @@ -2039,5 +2034,5 @@ export type { TwoFactorAuthNavigatorParamList, ConsoleNavigatorParamList, WorkspaceScreenName, - SettingsTabScreen, + SettingsTabScreenName, }; From 46924e1dcaa07c43f45eb8ff2e372367391e5ef6 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Wed, 9 Apr 2025 14:25:58 +0200 Subject: [PATCH 12/12] updated constant --- src/CONST.ts | 2 +- src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 05e4eca6e8394..2703de383dd05 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6312,7 +6312,7 @@ const CONST = { ACTIVE_WORKSPACE_ID: 'ACTIVE_WORKSPACE_ID', RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', - LAST_VISITED_SETTINGS_PATH: 'LAST_VISITED_SETTINGS_PATH', + LAST_VISITED_SETTINGS_TAB_PATH: 'LAST_VISITED_SETTINGS_TAB_PATH', }, RESERVATION_TYPE: { diff --git a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts index e1312610ff9f2..b5540400019cd 100644 --- a/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts +++ b/src/libs/Navigation/helpers/getLastVisitedWorkspace/index.ts @@ -5,11 +5,11 @@ import CONST from '@src/CONST'; import type {Route} from '@src/ROUTES'; function saveSettingsTabPathToSessionStorage(url: string) { - sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH, url); + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_TAB_PATH, url); } function getSettingsTabStateFromSessionStorage(): PartialState | undefined { - const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_PATH); + const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_TAB_PATH); if (!lastVisitedSettingsPath) { return undefined; }