diff --git a/src/CONST.ts b/src/CONST.ts index 95f762653402..dcef6d01f36c 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 0e40fa4d4037..476bdc999bc3 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(CONST.REGEX.REPORT_ID_FROM_PATH)?.at(1); + } + + if (!initialReportID) { + initialReportID = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID)?.reportID; + } + isInitialRender.current = false; } @@ -471,7 +488,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie