-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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: WS switcher and LHN are not reset to Expensify after leaving #45285
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bc0168d
Fix: WS switcher and LHN are not reset to Expensify after leaving
truph01 f306ab2
Fix: Move effect to BottomTabNavigator
truph01 d554f68
Fix: Only subscribe active workspace ID
truph01 f490e28
merge main
truph01 2778283
Fix: Resolve conflict
truph01 ddd1819
merge main
truph01 6c2550f
Fix: Move useEffect to BaseSidebarScreen
truph01 6885046
Fix: Lint
truph01 9253a2c
Fix: Lint
truph01 92bb5aa
Fix: Lint
truph01 08f2deb
rename variable
truph01 6e76a9d
Feat: Merge latest main
truph01 baaca67
Feat: Remove didResetActiveWorkspaceIDRef
truph01 e1c650d
Feat: Move useOnyx before useEffect
truph01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import {useNavigationState} from '@react-navigation/native'; | ||
import type {StackNavigationOptions} from '@react-navigation/stack'; | ||
import React from 'react'; | ||
import React, {useEffect} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import useActiveWorkspace from '@hooks/useActiveWorkspace'; | ||
import usePrevious from '@hooks/usePrevious'; | ||
import {updateLastAccessedWorkspace} from '@libs/actions/Policy/Policy'; | ||
import createCustomBottomTabNavigator from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator'; | ||
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {BottomTabNavigatorParamList, CentralPaneName, NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; | ||
import SidebarScreen from '@pages/home/sidebar/SidebarScreen'; | ||
import SearchPageBottomTab from '@pages/Search/SearchPageBottomTab'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import SCREENS from '@src/SCREENS'; | ||
import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; | ||
import ActiveRouteContext from './ActiveRouteContext'; | ||
|
@@ -20,6 +26,19 @@ const screenOptions: StackNavigationOptions = { | |
|
||
function BottomTabNavigator() { | ||
const activeRoute = useNavigationState<RootStackParamList, NavigationPartialRoute<CentralPaneName> | undefined>(getTopmostCentralPaneRoute); | ||
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subscribe only to the active workspace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated PR |
||
const {activeWorkspaceID} = useActiveWorkspace(); | ||
const selectedPolicy = Object.values(policies ?? {}).find((o) => o?.id === activeWorkspaceID); | ||
const prevSelectedPolicy = usePrevious(selectedPolicy); | ||
useEffect(() => { | ||
if (!selectedPolicy && !prevSelectedPolicy) { | ||
return; | ||
} | ||
if (prevSelectedPolicy && !selectedPolicy && activeWorkspaceID !== undefined) { | ||
Navigation.navigateWithSwitchPolicyID({policyID: undefined}); | ||
updateLastAccessedWorkspace(undefined); | ||
} | ||
}, [prevSelectedPolicy, selectedPolicy, activeWorkspaceID]); | ||
|
||
return ( | ||
<ActiveRouteContext.Provider value={activeRoute}> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this changed supposed to be on the SidebarScreen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the SidebarScreen is always mounted again once we leave the workspace then return to LHN. Because it is mounted again, so the logic:
that used in my solution is always
false
because both of them areundefined
when we leave the workspace then return to LHN.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the logic back to the Sidebar and in the useEffect only check for the current selected policy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@s77rt As I said above, we cannot move the logic to Sidebar. Can you help check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we can't go with the suggested solution above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should check only the current selected policy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you mean we should
!selectedPolicy
instead of!selectedPolicy && !prevSelectedPolicy
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes