From f13df4cef3dad8875de1d597f3430bd82e27b63c Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 4 Oct 2024 18:48:00 +0800 Subject: [PATCH] fix categories page always show loader when open the page --- src/pages/workspace/withPolicyConnections.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/withPolicyConnections.tsx b/src/pages/workspace/withPolicyConnections.tsx index 127631bc5437..f681193444c7 100644 --- a/src/pages/workspace/withPolicyConnections.tsx +++ b/src/pages/workspace/withPolicyConnections.tsx @@ -8,6 +8,7 @@ import usePrevious from '@hooks/usePrevious'; import {openPolicyAccountingPage} from '@libs/actions/PolicyConnections'; import ONYXKEYS from '@src/ONYXKEYS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import withPolicy from './withPolicy'; import type {WithPolicyProps} from './withPolicy'; @@ -28,11 +29,10 @@ type WithPolicyConnectionsProps = WithPolicyProps & { function withPolicyConnections(WrappedComponent: ComponentType, shouldBlockView = true) { function WithPolicyConnections(props: TProps) { const {isOffline} = useNetwork(); - const [hasConnectionsDataBeenFetched] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id ?? '-1'}`, { - initWithStoredValues: false, - }); + const [hasConnectionsDataBeenFetched, hasConnectionsDataBeenFetchedResult] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id ?? '-1'}`); + const isOnyxDataLoading = isLoadingOnyxValue(hasConnectionsDataBeenFetchedResult); const isConnectionDataFetchNeeded = - !isOffline && !!props.policy && (!!props.policy.areConnectionsEnabled || !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched; + !isOnyxDataLoading && !isOffline && !!props.policy && (!!props.policy.areConnectionsEnabled || !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched; const [isFetchingData, setIsFetchingData] = useState(false); @@ -55,7 +55,7 @@ function withPolicyConnections(Wrappe openPolicyAccountingPage(props.policy.id); }, [props.policy?.id, isConnectionDataFetchNeeded]); - if ((isConnectionDataFetchNeeded || isFetchingData) && shouldBlockView) { + if ((isConnectionDataFetchNeeded || isFetchingData || isOnyxDataLoading) && shouldBlockView) { return ; }