Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/pages/home/sidebar/BaseSidebarScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {updateLastAccessedWorkspace} from '@libs/actions/Policy/Policy';
import * as Browser from '@libs/Browser';
import {isMobile} from '@libs/Browser';
import getInitialSplitNavigatorState from '@libs/Navigation/AppNavigator/createSplitNavigator/getInitialSplitNavigatorState';
import {getPreservedSplitNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveSplitNavigatorState';
import getTopmostReportsSplitNavigator from '@libs/Navigation/helpers/getTopmostReportsSplitNavigator';
Expand Down Expand Up @@ -39,20 +39,17 @@ function BaseSidebarScreen() {
}, []);

useEffect(() => {
if (!!activeWorkspace || activeWorkspaceID === undefined || isLoading) {
return;
}

// Otherwise, if the workspace is already loaded, we don't need to do anything
const topmostReport = getTopmostReportsSplitNavigator();
const topmostReportSplit = getTopmostReportsSplitNavigator();
const topmostReportSplitPolicyID = topmostReportSplit?.params && `policyID` in topmostReportSplit.params ? topmostReportSplit.params.policyID : undefined;
const hasWorkspaceBeenDeleted = !activeWorkspace && activeWorkspaceResult.status === 'loaded' && !!topmostReportSplitPolicyID;

if (!topmostReport) {
if (!topmostReportSplit || !hasWorkspaceBeenDeleted || isLoading) {
return;
}

// Switching workspace to global should only be performed from the currently opened sidebar screen
const topmostReportState = topmostReport?.state ?? getPreservedSplitNavigatorState(topmostReport?.key);
const isCurrentSidebar = topmostReportState?.routes.some((route) => currentRoute.key === route.key);
const topmostReportSplitState = topmostReportSplit?.state ?? getPreservedSplitNavigatorState(topmostReportSplit?.key);
const isCurrentSidebar = topmostReportSplitState?.routes.some((route) => currentRoute.key === route.key);

if (!isCurrentSidebar) {
return;
Expand All @@ -61,14 +58,14 @@ function BaseSidebarScreen() {
const reportsSplitNavigatorWithoutPolicyID = getInitialSplitNavigatorState({name: SCREENS.HOME}, {name: SCREENS.REPORT});
Navigation.replaceWithSplitNavigator(reportsSplitNavigatorWithoutPolicyID);
updateLastAccessedWorkspace(undefined);
}, [activeWorkspace, activeWorkspaceID, isLoading, currentRoute.key]);
}, [activeWorkspace, isLoading, currentRoute.key, activeWorkspaceResult]);

const shouldDisplaySearch = shouldUseNarrowLayout;

return (
<ScreenWrapper
shouldEnableKeyboardAvoidingView={false}
style={[styles.sidebar, Browser.isMobile() ? styles.userSelectNone : {}]}
style={[styles.sidebar, isMobile() ? styles.userSelectNone : {}]}
testID={BaseSidebarScreen.displayName}
bottomContent={<BottomTabBar selectedTab={BOTTOM_TABS.HOME} />}
>
Expand Down