Skip to content

Commit

Permalink
trigger useEffect when online status changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayata Suenaga committed Apr 21, 2024
1 parent bc91a7f commit 76ec54a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pages/workspace/withPolicyConnections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {ComponentType} from 'react';
import {useOnyx} from 'react-native-onyx';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useNetwork from '@hooks/useNetwork';
import {openPolicyAccountingPage} from '@libs/actions/PolicyConnections';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
Expand All @@ -23,6 +24,7 @@ type WithPolicyConnectionsProps = WithPolicyProps;
*/
function withPolicyConnections(WrappedComponent: ComponentType<WithPolicyConnectionsProps & {policy: Policy}>) {
function WithPolicyConnections({policy, policyDraft, route}: WithPolicyConnectionsProps) {
const {isOffline} = useNetwork();
const [hasConnectionsDataBeenFetched, {status}] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${policy?.id ?? '0'}`, {
initWithStoredValues: false,
});
Expand All @@ -35,7 +37,7 @@ function withPolicyConnections(WrappedComponent: ComponentType<WithPolicyConnect
}

openPolicyAccountingPage(policy.id);
}, [hasConnectionsDataBeenFetched, policy]);
}, [hasConnectionsDataBeenFetched, policy, isOffline]);

if (!policy || status === 'loading' || !hasConnectionsDataBeenFetched) {
return (
Expand Down

0 comments on commit 76ec54a

Please sign in to comment.