From 80ae175f3badfa7635e22063d4075ee237f8999e Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 28 May 2024 22:00:54 +0800 Subject: [PATCH 1/2] replace withOnyx with useOnyx --- .../createCustomBottomTabNavigator/TopBar.tsx | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx index 68cadc8cd4d8..00893b7990ce 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx @@ -1,7 +1,6 @@ import React from 'react'; import {View} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import Breadcrumbs from '@components/Breadcrumbs'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -17,20 +16,15 @@ import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Policy, Session as SessionType} from '@src/types/onyx'; -type TopBarOnyxProps = { - policy: OnyxEntry; - session: OnyxEntry>; -}; +type TopBarProps = {breadcrumbLabel: string; activeWorkspaceID?: string; shouldDisplaySearch?: boolean}; -// eslint-disable-next-line react/no-unused-prop-types -type TopBarProps = {breadcrumbLabel: string; activeWorkspaceID?: string; shouldDisplaySearch?: boolean} & TopBarOnyxProps; - -function TopBar({policy, session, breadcrumbLabel, shouldDisplaySearch = true}: TopBarProps) { +function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true}: TopBarProps) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID}`); + const [session] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session && {authTokenType: session.authTokenType}}); const isAnonymousUser = Session.isAnonymousUser(session); const headerBreadcrumb = policy?.name @@ -84,12 +78,4 @@ function TopBar({policy, session, breadcrumbLabel, shouldDisplaySearch = true}: TopBar.displayName = 'TopBar'; -export default withOnyx({ - policy: { - key: ({activeWorkspaceID}) => `${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID}`, - }, - session: { - key: ONYXKEYS.SESSION, - selector: (session) => session && {authTokenType: session.authTokenType}, - }, -})(TopBar); +export default TopBar; From 73ea407e86d53671608146f2e71d32f2557bb464 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 28 May 2024 22:32:33 +0800 Subject: [PATCH 2/2] rename --- .../AppNavigator/createCustomBottomTabNavigator/TopBar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx index 00893b7990ce..81022842a03d 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx @@ -24,7 +24,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true} const theme = useTheme(); const {translate} = useLocalize(); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID}`); - const [session] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session && {authTokenType: session.authTokenType}}); + const [session] = useOnyx(ONYXKEYS.SESSION, {selector: (sessionValue) => sessionValue && {authTokenType: sessionValue.authTokenType}}); const isAnonymousUser = Session.isAnonymousUser(session); const headerBreadcrumb = policy?.name