1
1
import React , { memo , useEffect , useMemo , useRef , useState } from 'react' ;
2
2
import { View } from 'react-native' ;
3
3
import type { OnyxEntry } from 'react-native-onyx' ;
4
- import Onyx , { useOnyx } from 'react-native-onyx' ;
4
+ import Onyx , { withOnyx } from 'react-native-onyx' ;
5
5
import type { ValueOf } from 'type-fest' ;
6
6
import ActiveGuidesEventListener from '@components/ActiveGuidesEventListener' ;
7
7
import ComposeProviders from '@components/ComposeProviders' ;
@@ -50,7 +50,6 @@ import SCREENS from '@src/SCREENS';
50
50
import type * as OnyxTypes from '@src/types/onyx' ;
51
51
import type { SelectedTimezone , Timezone } from '@src/types/onyx/PersonalDetails' ;
52
52
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
53
- import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue' ;
54
53
import type ReactComponentModule from '@src/types/utils/ReactComponentModule' ;
55
54
import beforeRemoveReportOpenedFromSearchRHP from './beforeRemoveReportOpenedFromSearchRHP' ;
56
55
import CENTRAL_PANE_SCREENS from './CENTRAL_PANE_SCREENS' ;
@@ -66,6 +65,17 @@ import OnboardingModalNavigator from './Navigators/OnboardingModalNavigator';
66
65
import RightModalNavigator from './Navigators/RightModalNavigator' ;
67
66
import WelcomeVideoModalNavigator from './Navigators/WelcomeVideoModalNavigator' ;
68
67
68
+ type AuthScreensProps = {
69
+ /** Session of currently logged in user */
70
+ session : OnyxEntry < OnyxTypes . Session > ;
71
+
72
+ /** The report ID of the last opened public room as anonymous user */
73
+ lastOpenedPublicRoomID : OnyxEntry < string > ;
74
+
75
+ /** The last Onyx update ID was applied to the client */
76
+ initialLastUpdateIDAppliedToClient : OnyxEntry < number > ;
77
+ } ;
78
+
69
79
const loadReportAttachments = ( ) => require < ReactComponentModule > ( '../../../pages/home/report/ReportAttachments' ) . default ;
70
80
const loadValidateLoginPage = ( ) => require < ReactComponentModule > ( '../../../pages/ValidateLoginPage' ) . default ;
71
81
const loadLogOutPreviousUserPage = ( ) => require < ReactComponentModule > ( '../../../pages/LogOutPreviousUserPage' ) . default ;
@@ -213,10 +223,7 @@ const modalScreenListenersWithCancelSearch = {
213
223
} ,
214
224
} ;
215
225
216
- function AuthScreens ( ) {
217
- const [ session , sessionStatus ] = useOnyx ( ONYXKEYS . SESSION ) ;
218
- const [ lastOpenedPublicRoomID , lastOpenedPublicRoomIDStatus ] = useOnyx ( ONYXKEYS . LAST_OPENED_PUBLIC_ROOM_ID ) ;
219
- const [ initialLastUpdateIDAppliedToClient , initialLastUpdateIDAppliedToClientStatus ] = useOnyx ( ONYXKEYS . ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT ) ;
226
+ function AuthScreens ( { session, lastOpenedPublicRoomID, initialLastUpdateIDAppliedToClient} : AuthScreensProps ) {
220
227
const styles = useThemeStyles ( ) ;
221
228
const StyleUtils = useStyleUtils ( ) ;
222
229
const { shouldUseNarrowLayout, onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth} = useResponsiveLayout ( ) ;
@@ -398,9 +405,6 @@ function AuthScreens() {
398
405
// Prevent unnecessary scrolling
399
406
cardStyle : styles . cardStyleNavigator ,
400
407
} ;
401
- if ( isLoadingOnyxValue ( sessionStatus , lastOpenedPublicRoomIDStatus , initialLastUpdateIDAppliedToClientStatus ) ) {
402
- return ;
403
- }
404
408
405
409
return (
406
410
< ComposeProviders components = { [ OptionsListContextProvider , SearchContextProvider ] } >
@@ -579,4 +583,16 @@ function AuthScreens() {
579
583
580
584
AuthScreens . displayName = 'AuthScreens' ;
581
585
582
- export default memo ( AuthScreens , ( ) => true ) ;
586
+ const AuthScreensMemoized = memo ( AuthScreens , ( ) => true ) ;
587
+
588
+ export default withOnyx < AuthScreensProps , AuthScreensProps > ( {
589
+ session : {
590
+ key : ONYXKEYS . SESSION ,
591
+ } ,
592
+ lastOpenedPublicRoomID : {
593
+ key : ONYXKEYS . LAST_OPENED_PUBLIC_ROOM_ID ,
594
+ } ,
595
+ initialLastUpdateIDAppliedToClient : {
596
+ key : ONYXKEYS . ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT ,
597
+ } ,
598
+ } ) ( AuthScreensMemoized ) ;
0 commit comments