Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prev workspace is shown when switching workspace #55443

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 8 additions & 12 deletions src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import {sortWorkspacesBySelected} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {isPolicyAdmin, shouldShowPolicy, sortWorkspacesBySelected} from '@libs/PolicyUtils';
import {getDefaultWorkspaceAvatar} from '@libs/ReportUtils';
import {getWorkspacesBrickRoads, getWorkspacesUnreadStatuses} from '@libs/WorkspacesSettingsUtils';
import type {BrickRoad} from '@libs/WorkspacesSettingsUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -89,13 +88,10 @@ function WorkspaceSwitcherPage() {
}
const newPolicyID = policyID === activeWorkspaceID ? undefined : policyID;

setActiveWorkspaceID(newPolicyID);
Navigation.goBack();
if (newPolicyID !== activeWorkspaceID) {
// On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while navigating back at the same time.
// Therefore we delay switching the workspace until after back navigation, using the InteractionManager.
switchPolicyAfterInteractions(newPolicyID);
}
// On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while navigating back at the same time.
// Therefore we delay switching the workspace until after back navigation, using the InteractionManager.
switchPolicyAfterInteractions(newPolicyID, () => setActiveWorkspaceID(newPolicyID));
},
[activeWorkspaceID, setActiveWorkspaceID, isFocused],
);
Expand All @@ -106,14 +102,14 @@ function WorkspaceSwitcherPage() {
}

return Object.values(policies)
.filter((policy) => PolicyUtils.shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending)
.filter((policy) => shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending)
.map((policy) => ({
text: policy?.name ?? '',
policyID: policy?.id,
brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id),
icons: [
{
source: policy?.avatarURL ? policy.avatarURL : ReportUtils.getDefaultWorkspaceAvatar(policy?.name),
source: policy?.avatarURL ? policy.avatarURL : getDefaultWorkspaceAvatar(policy?.name),
fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
name: policy?.name,
type: CONST.ICON_TYPE_WORKSPACE,
Expand All @@ -122,7 +118,7 @@ function WorkspaceSwitcherPage() {
],
isBold: hasUnreadData(policy?.id),
keyForList: policy?.id,
isPolicyAdmin: PolicyUtils.isPolicyAdmin(policy),
isPolicyAdmin: isPolicyAdmin(policy),
isSelected: activeWorkspaceID === policy?.id,
}));
}, [policies, isOffline, currentUserLogin, getIndicatorTypeForPolicy, hasUnreadData, activeWorkspaceID]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {InteractionManager} from 'react-native';
import Navigation from '@libs/Navigation/Navigation';

function switchPolicyAfterInteractions(newPolicyID: string | undefined) {
function switchPolicyAfterInteractions(newPolicyID: string | undefined, setActiveWorkspaceID: () => void) {
InteractionManager.runAfterInteractions(() => {
setActiveWorkspaceID();
Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Navigation from '@libs/Navigation/Navigation';

function switchPolicyAfterInteractions(newPolicyID: string | undefined) {
function switchPolicyAfterInteractions(newPolicyID: string | undefined, setActiveWorkspaceID: () => void) {
setActiveWorkspaceID();
Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID});
}

Expand Down
Loading