Skip to content

Commit

Permalink
get rid of withOnyx
Browse files Browse the repository at this point in the history
  • Loading branch information
jnowakow committed Nov 18, 2024
1 parent 5e30c9b commit b6ca6db
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/components/InitialURLContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, {createContext, useEffect, useMemo, useState} from 'react';
import type {ReactNode} from 'react';
import {Linking} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import {signInAfterTransitionFromOldDot} from '@libs/actions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -20,24 +19,22 @@ const InitialURLContext = createContext<InitialUrlContextType>({
setInitialURL: () => {},
});

type InitialURLContextProviderPropsFromOnyx = {
/** In order to reconnect ND in hybrid app from right place */
initialLastUpdateIDAppliedToClient: OnyxEntry<number>;
};

type InitialURLContextProviderProps = InitialURLContextProviderPropsFromOnyx & {
type InitialURLContextProviderProps = {
/** URL passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. */
url?: Route;

/** Children passed to the context provider */
children: ReactNode;
};

function InitialURLContextProvider({children, url, initialLastUpdateIDAppliedToClient}: InitialURLContextProviderProps) {
function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) {
const [initialURL, setInitialURL] = useState<Route | undefined>();
const {setSplashScreenState} = useSplashScreenStateContext();

const [initialLastUpdateIDAppliedToClient, metadata] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT);
useEffect(() => {
if (metadata.status !== 'loaded') {
return;
}
if (url) {
signInAfterTransitionFromOldDot(url, initialLastUpdateIDAppliedToClient).then((route) => {
setInitialURL(route);
Expand All @@ -48,7 +45,7 @@ function InitialURLContextProvider({children, url, initialLastUpdateIDAppliedToC
Linking.getInitialURL().then((initURL) => {
setInitialURL(initURL as Route);
});
}, [initialLastUpdateIDAppliedToClient, setSplashScreenState, url]);
}, [initialLastUpdateIDAppliedToClient, metadata.status, setSplashScreenState, url]);

const initialUrlContext = useMemo(
() => ({
Expand All @@ -63,11 +60,6 @@ function InitialURLContextProvider({children, url, initialLastUpdateIDAppliedToC

InitialURLContextProvider.displayName = 'InitialURLContextProvider';

// this `withOnyx` is used intentionally because we want to delay rendering until the last update's id is available for the app
export default withOnyx<InitialURLContextProviderProps, InitialURLContextProviderPropsFromOnyx>({
initialLastUpdateIDAppliedToClient: {
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
},
})(InitialURLContextProvider);
export default InitialURLContextProvider;

export {InitialURLContext};

0 comments on commit b6ca6db

Please sign in to comment.