From 3246551bfd868bd0dca1ff47377befb2dec774a1 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 16 Jul 2024 15:23:08 -0700 Subject: [PATCH 1/2] Fix initial reportID in AuthScreens --- .../Navigation/AppNavigator/AuthScreens.tsx | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 0e40fa4d4037..ae872d207f32 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -4,7 +4,9 @@ import type {OnyxEntry} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import OptionsListContextProvider from '@components/OptionListContextProvider'; +import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useOnboardingLayout from '@hooks/useOnboardingLayout'; +import usePermissions from '@hooks/usePermissions'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; @@ -19,6 +21,7 @@ import type {AuthScreensParamList, CentralPaneName, CentralPaneScreensParamList} import NetworkConnection from '@libs/NetworkConnection'; import * as Pusher from '@libs/Pusher/pusher'; import PusherConnectionManager from '@libs/PusherConnectionManager'; +import * as ReportUtils from '@libs/ReportUtils'; import * as SessionUtils from '@libs/SessionUtils'; import ConnectionCompletePage from '@pages/ConnectionCompletePage'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; @@ -82,7 +85,7 @@ function shouldOpenOnAdminRoom() { return url ? new URL(url).searchParams.get('openOnAdminRoom') === 'true' : false; } -function getCentralPaneScreenInitialParams(screenName: CentralPaneName): Partial> { +function getCentralPaneScreenInitialParams(screenName: CentralPaneName, initialReportID?: string): Partial> { if (screenName === SCREENS.SEARCH.CENTRAL_PANE) { return {sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE, sortOrder: CONST.SEARCH.SORT_ORDER.DESC}; } @@ -90,6 +93,7 @@ function getCentralPaneScreenInitialParams(screenName: CentralPaneName): Partial if (screenName === SCREENS.REPORT) { return { openOnAdminRoom: shouldOpenOnAdminRoom() ? true : undefined, + reportID: initialReportID, }; } @@ -197,15 +201,28 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie const {isSmallScreenWidth} = useWindowDimensions(); const {shouldUseNarrowLayout} = useOnboardingLayout(); const screenOptions = getRootNavigatorScreenOptions(isSmallScreenWidth, styles, StyleUtils); + const {canUseDefaultRooms} = usePermissions(); + const {activeWorkspaceID} = useActiveWorkspace(); const onboardingModalScreenOptions = useMemo(() => screenOptions.onboardingModalNavigator(shouldUseNarrowLayout), [screenOptions, shouldUseNarrowLayout]); const onboardingScreenOptions = useMemo( () => getOnboardingModalScreenOptions(isSmallScreenWidth, styles, StyleUtils, shouldUseNarrowLayout), [StyleUtils, isSmallScreenWidth, shouldUseNarrowLayout, styles], ); - const isInitialRender = useRef(true); + let initialReportID: string | undefined; + const isInitialRender = useRef(true); if (isInitialRender.current) { Timing.start(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); + + const currentURL = getCurrentUrl(); + if (currentURL) { + initialReportID = new URL(currentURL).pathname.match(/\/r\/(\d+)/)?.at(1); + } + + if (!initialReportID) { + initialReportID = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID)?.reportID; + } + isInitialRender.current = false; } @@ -471,7 +488,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie From 35fc793b751f35ecd38935aed36dfb424ab87185 Mon Sep 17 00:00:00 2001 From: rory Date: Wed, 17 Jul 2024 02:09:13 -0700 Subject: [PATCH 2/2] Move regex to CONST.REGEX --- src/CONST.ts | 2 ++ src/libs/Navigation/AppNavigator/AuthScreens.tsx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index 3f141905e84c..425da1d4b38e 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2346,6 +2346,8 @@ const CONST = { POLICY_ID_FROM_PATH: /\/w\/([a-zA-Z0-9]+)(\/|$)/, SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*(?![^\`]*\`)`, 'gim'), + + REPORT_ID_FROM_PATH: /\/r\/(\d+)/, }, PRONOUNS: { diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index ae872d207f32..476bdc999bc3 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -216,7 +216,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie const currentURL = getCurrentUrl(); if (currentURL) { - initialReportID = new URL(currentURL).pathname.match(/\/r\/(\d+)/)?.at(1); + initialReportID = new URL(currentURL).pathname.match(CONST.REGEX.REPORT_ID_FROM_PATH)?.at(1); } if (!initialReportID) {