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

chore: migrate AuthScreens from withOnyx to useOnyx #49185

Merged
merged 21 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
43746db
chore: migrate withOnyx to useOnyx
BhuvaneshPatil Sep 13, 2024
4df69bb
lint fix
BhuvaneshPatil Sep 13, 2024
72c8de9
Merge branch 'main' of https://github.com/Expensify/App into 49103-on…
BhuvaneshPatil Sep 13, 2024
94b1edd
revert podfile changes
BhuvaneshPatil Sep 13, 2024
b727cc4
revert podfile changes
BhuvaneshPatil Sep 13, 2024
250275b
fix showing indicator
BhuvaneshPatil Sep 16, 2024
b7c4821
Merge branch 'main' of https://github.com/Expensify/App into 49103-on…
BhuvaneshPatil Sep 16, 2024
6dc4b1b
Merge branch 'main' of https://github.com/Expensify/App into 49103-on…
BhuvaneshPatil Sep 16, 2024
126c750
Merge branch 'main' of https://github.com/Expensify/App into 49103-on…
BhuvaneshPatil Sep 17, 2024
e605f51
refactoring
BhuvaneshPatil Sep 18, 2024
e00d4c6
chore: migrate withOnyx to useOnyx
BhuvaneshPatil Sep 13, 2024
ba4e4ca
lint fix
BhuvaneshPatil Sep 13, 2024
61afdee
revert podfile changes
BhuvaneshPatil Sep 13, 2024
003585e
revert podfile changes
BhuvaneshPatil Sep 13, 2024
34dd64d
modify
BhuvaneshPatil Sep 18, 2024
4f3af39
refactoring
BhuvaneshPatil Sep 18, 2024
b5a4e3a
fix tests
BhuvaneshPatil Sep 25, 2024
698d2c9
Merge branch '49103-onyx-migration' of https://github.com/BhuvaneshPa…
BhuvaneshPatil Sep 25, 2024
f24a9e6
Merge branch 'main' of https://github.com/Expensify/App into 49103-on…
BhuvaneshPatil Sep 25, 2024
de337ac
fix lint
BhuvaneshPatil Sep 25, 2024
99edd39
fix test
BhuvaneshPatil Sep 25, 2024
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
36 changes: 10 additions & 26 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {memo, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx, {withOnyx} from 'react-native-onyx';
import Onyx, {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import ActiveGuidesEventListener from '@components/ActiveGuidesEventListener';
import ComposeProviders from '@components/ComposeProviders';
Expand Down Expand Up @@ -50,6 +50,7 @@ import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
import beforeRemoveReportOpenedFromSearchRHP from './beforeRemoveReportOpenedFromSearchRHP';
import CENTRAL_PANE_SCREENS from './CENTRAL_PANE_SCREENS';
Expand All @@ -65,17 +66,6 @@ import OnboardingModalNavigator from './Navigators/OnboardingModalNavigator';
import RightModalNavigator from './Navigators/RightModalNavigator';
import WelcomeVideoModalNavigator from './Navigators/WelcomeVideoModalNavigator';

type AuthScreensProps = {
/** Session of currently logged in user */
session: OnyxEntry<OnyxTypes.Session>;

/** The report ID of the last opened public room as anonymous user */
lastOpenedPublicRoomID: OnyxEntry<string>;

/** The last Onyx update ID was applied to the client */
initialLastUpdateIDAppliedToClient: OnyxEntry<number>;
};

const loadReportAttachments = () => require<ReactComponentModule>('../../../pages/home/report/ReportAttachments').default;
const loadValidateLoginPage = () => require<ReactComponentModule>('../../../pages/ValidateLoginPage').default;
const loadLogOutPreviousUserPage = () => require<ReactComponentModule>('../../../pages/LogOutPreviousUserPage').default;
Expand Down Expand Up @@ -223,7 +213,10 @@ const modalScreenListenersWithCancelSearch = {
},
};

function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDAppliedToClient}: AuthScreensProps) {
function AuthScreens() {
const [session, sessionStatus] = useOnyx(ONYXKEYS.SESSION);
const [lastOpenedPublicRoomID, lastOpenedPublicRoomIDStatus] = useOnyx(ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID);
const [initialLastUpdateIDAppliedToClient, initialLastUpdateIDAppliedToClientStatus] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT);
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {shouldUseNarrowLayout, onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth} = useResponsiveLayout();
Expand Down Expand Up @@ -405,6 +398,9 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
// Prevent unnecessary scrolling
cardStyle: styles.cardStyleNavigator,
};
if (isLoadingOnyxValue(sessionStatus, lastOpenedPublicRoomIDStatus, initialLastUpdateIDAppliedToClientStatus)) {
return;
}

return (
<ComposeProviders components={[OptionsListContextProvider, SearchContextProvider]}>
Expand Down Expand Up @@ -583,16 +579,4 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie

AuthScreens.displayName = 'AuthScreens';

const AuthScreensMemoized = memo(AuthScreens, () => true);

export default withOnyx<AuthScreensProps, AuthScreensProps>({
session: {
key: ONYXKEYS.SESSION,
},
lastOpenedPublicRoomID: {
key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID,
},
initialLastUpdateIDAppliedToClient: {
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
},
})(AuthScreensMemoized);
export default memo(AuthScreens, () => true);
4 changes: 4 additions & 0 deletions tests/ui/PaginationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ async function signInAndGetApp(): Promise<void> {
},
});

await Onyx.set(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, 1);

await Onyx.set(ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, '1');

// We manually setting the sidebar as loaded since the onLayout event does not fire in tests
AppActions.setSidebarLoaded();
});
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ function signInAndGetAppWithUnreadChat(): Promise<void> {
[USER_B_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_B_EMAIL, USER_B_ACCOUNT_ID, 'B'),
});

await Onyx.set(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, 1);

await Onyx.set(ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, '1');

// We manually setting the sidebar as loaded since the onLayout event does not fire in tests
AppActions.setSidebarLoaded();
return waitForBatchedUpdatesWithAct();
Expand Down
Loading