From bc0168d57990c497bae024689a32df882309c5f7 Mon Sep 17 00:00:00 2001 From: truph01 Date: Thu, 11 Jul 2024 21:20:44 +0700 Subject: [PATCH 1/9] Fix: WS switcher and LHN are not reset to Expensify after leaving --- .../SidebarScreen/BaseSidebarScreen.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index f0fa320c1483..435902ec4924 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -1,15 +1,20 @@ import React, {useEffect} from 'react'; import {View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import ScreenWrapper from '@components/ScreenWrapper'; import useActiveWorkspaceFromNavigationState from '@hooks/useActiveWorkspaceFromNavigationState'; import useLocalize from '@hooks/useLocalize'; +import usePrevious from '@hooks/usePrevious'; import useThemeStyles from '@hooks/useThemeStyles'; +import {updateLastAccessedWorkspace} from '@libs/actions/Policy/Policy'; import * as Browser from '@libs/Browser'; import TopBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar'; +import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData'; import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; /** * Function called when a pinned chat is selected. @@ -29,6 +34,19 @@ function BaseSidebarScreen() { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); }, []); + const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + 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 ( Date: Thu, 11 Jul 2024 22:38:06 +0700 Subject: [PATCH 2/9] Fix: Move effect to BottomTabNavigator --- .../Navigators/BottomTabNavigator.tsx | 21 ++++++++++++++++++- .../SidebarScreen/BaseSidebarScreen.tsx | 18 ---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx index 46212f3bc41f..2881d9aefc1c 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx @@ -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 | undefined>(getTopmostCentralPaneRoute); + const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + 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 ( diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 435902ec4924..f0fa320c1483 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -1,20 +1,15 @@ import React, {useEffect} from 'react'; import {View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; import ScreenWrapper from '@components/ScreenWrapper'; import useActiveWorkspaceFromNavigationState from '@hooks/useActiveWorkspaceFromNavigationState'; import useLocalize from '@hooks/useLocalize'; -import usePrevious from '@hooks/usePrevious'; import useThemeStyles from '@hooks/useThemeStyles'; -import {updateLastAccessedWorkspace} from '@libs/actions/Policy/Policy'; import * as Browser from '@libs/Browser'; import TopBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar'; -import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData'; import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; /** * Function called when a pinned chat is selected. @@ -34,19 +29,6 @@ function BaseSidebarScreen() { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); }, []); - const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - 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 ( Date: Wed, 24 Jul 2024 23:10:38 +0700 Subject: [PATCH 3/9] Fix: Move useEffect to BaseSidebarScreen --- .../Navigators/BottomTabNavigator.tsx | 20 +------------------ .../SidebarScreen/BaseSidebarScreen.tsx | 16 ++++++++++++++- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx index 3d3b2ce82c59..30e8d4c668c6 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx @@ -1,17 +1,11 @@ import {useNavigationState} from '@react-navigation/native'; import type {StackNavigationOptions} from '@react-navigation/stack'; -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 React from 'react'; 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 ActiveCentralPaneRouteContext from './ActiveCentralPaneRouteContext'; @@ -25,18 +19,6 @@ const screenOptions: StackNavigationOptions = { }; function BottomTabNavigator() { - const {activeWorkspaceID} = useActiveWorkspace(); - const [selectedPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); - const prevSelectedPolicy = usePrevious(selectedPolicy); - useEffect(() => { - if (!selectedPolicy && !prevSelectedPolicy) { - return; - } - if (prevSelectedPolicy && !selectedPolicy && activeWorkspaceID !== undefined) { - Navigation.navigateWithSwitchPolicyID({policyID: undefined}); - updateLastAccessedWorkspace(undefined); - } - }, [prevSelectedPolicy, selectedPolicy, activeWorkspaceID]); const activeRoute = useNavigationState | undefined>(getTopmostCentralPaneRoute); return ( diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index f0fa320c1483..1d2c3213ad15 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -1,15 +1,19 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useRef} from 'react'; import {View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import ScreenWrapper from '@components/ScreenWrapper'; import useActiveWorkspaceFromNavigationState from '@hooks/useActiveWorkspaceFromNavigationState'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import {updateLastAccessedWorkspace} from '@libs/actions/Policy/Policy'; import * as Browser from '@libs/Browser'; import TopBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar'; +import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData'; import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; /** * Function called when a pinned chat is selected. @@ -23,12 +27,22 @@ function BaseSidebarScreen() { const styles = useThemeStyles(); const activeWorkspaceID = useActiveWorkspaceFromNavigationState(); const {translate} = useLocalize(); + const didResetActiveWorkspaceIDRef = useRef(false); useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); }, []); + const [selectedPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); + useEffect(() => { + if (!selectedPolicy && activeWorkspaceID !== undefined && !didResetActiveWorkspaceIDRef.current) { + Navigation.navigateWithSwitchPolicyID({policyID: undefined}); + updateLastAccessedWorkspace(undefined); + didResetActiveWorkspaceIDRef.current = true; + } + }, [selectedPolicy, activeWorkspaceID]); + return ( Date: Wed, 24 Jul 2024 23:22:10 +0700 Subject: [PATCH 4/9] Fix: Lint --- .../home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 1d2c3213ad15..8f0bbbcac065 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -35,12 +35,15 @@ function BaseSidebarScreen() { }, []); const [selectedPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); + useEffect(() => { - if (!selectedPolicy && activeWorkspaceID !== undefined && !didResetActiveWorkspaceIDRef.current) { - Navigation.navigateWithSwitchPolicyID({policyID: undefined}); - updateLastAccessedWorkspace(undefined); - didResetActiveWorkspaceIDRef.current = true; + if (selectedPolicy || activeWorkspaceID === undefined || didResetActiveWorkspaceIDRef.current) { + return; } + + Navigation.navigateWithSwitchPolicyID({policyID: undefined}); + updateLastAccessedWorkspace(undefined); + didResetActiveWorkspaceIDRef.current = true; }, [selectedPolicy, activeWorkspaceID]); return ( From 9253a2c1bb509952299ece6792da01394e44e70c Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 24 Jul 2024 23:33:28 +0700 Subject: [PATCH 5/9] Fix: Lint --- src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 8f0bbbcac065..2c23cd900f4c 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -37,7 +37,7 @@ function BaseSidebarScreen() { const [selectedPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); useEffect(() => { - if (selectedPolicy || activeWorkspaceID === undefined || didResetActiveWorkspaceIDRef.current) { + if (selectedPolicy || activeWorkspaceID === undefined || !!didResetActiveWorkspaceIDRef.current) { return; } From 92bb5aa32e2f33442cd205f490e5835bb7b9d1f8 Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 24 Jul 2024 23:58:03 +0700 Subject: [PATCH 6/9] Fix: Lint --- src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 2c23cd900f4c..463076095958 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -37,7 +37,7 @@ function BaseSidebarScreen() { const [selectedPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); useEffect(() => { - if (selectedPolicy || activeWorkspaceID === undefined || !!didResetActiveWorkspaceIDRef.current) { + if (!!selectedPolicy || activeWorkspaceID === undefined || !!didResetActiveWorkspaceIDRef.current) { return; } From 08f2debcf869ded1c68495567f97e1c40a69361d Mon Sep 17 00:00:00 2001 From: truph01 Date: Thu, 25 Jul 2024 22:40:56 +0700 Subject: [PATCH 7/9] rename variable --- src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 463076095958..3264a2f3434c 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -34,17 +34,17 @@ function BaseSidebarScreen() { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); }, []); - const [selectedPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); + const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); useEffect(() => { - if (!!selectedPolicy || activeWorkspaceID === undefined || !!didResetActiveWorkspaceIDRef.current) { + if (!!activeWorkspace || activeWorkspaceID === undefined || !!didResetActiveWorkspaceIDRef.current) { return; } Navigation.navigateWithSwitchPolicyID({policyID: undefined}); updateLastAccessedWorkspace(undefined); didResetActiveWorkspaceIDRef.current = true; - }, [selectedPolicy, activeWorkspaceID]); + }, [activeWorkspace, activeWorkspaceID]); return ( Date: Tue, 30 Jul 2024 17:22:28 +0700 Subject: [PATCH 8/9] Feat: Remove didResetActiveWorkspaceIDRef --- src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 3264a2f3434c..c1027c665adf 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useRef} from 'react'; +import React, {useEffect} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -27,7 +27,6 @@ function BaseSidebarScreen() { const styles = useThemeStyles(); const activeWorkspaceID = useActiveWorkspaceFromNavigationState(); const {translate} = useLocalize(); - const didResetActiveWorkspaceIDRef = useRef(false); useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); @@ -37,13 +36,12 @@ function BaseSidebarScreen() { const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); useEffect(() => { - if (!!activeWorkspace || activeWorkspaceID === undefined || !!didResetActiveWorkspaceIDRef.current) { + if (!!activeWorkspace || activeWorkspaceID === undefined) { return; } Navigation.navigateWithSwitchPolicyID({policyID: undefined}); updateLastAccessedWorkspace(undefined); - didResetActiveWorkspaceIDRef.current = true; }, [activeWorkspace, activeWorkspaceID]); return ( From e1c650d1bc45da9fa81fd1abf69684989973b115 Mon Sep 17 00:00:00 2001 From: truph01 Date: Tue, 30 Jul 2024 23:50:59 +0700 Subject: [PATCH 9/9] Feat: Move useOnyx before useEffect --- src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index c1027c665adf..597318ab2b26 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -27,14 +27,13 @@ function BaseSidebarScreen() { const styles = useThemeStyles(); const activeWorkspaceID = useActiveWorkspaceFromNavigationState(); const {translate} = useLocalize(); + const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); }, []); - const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); - useEffect(() => { if (!!activeWorkspace || activeWorkspaceID === undefined) { return;