Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ const ONYXKEYS = {
/** Set when we are loading payment methods */
IS_LOADING_PAYMENT_METHODS: 'isLoadingPaymentMethods',

/** Is report data loading? */
IS_LOADING_REPORT_DATA: 'isLoadingReportData',

/** Is report data loading? */
IS_LOADING_APP: 'isLoadingApp',

Expand Down Expand Up @@ -1107,7 +1104,6 @@ type OnyxValuesMapping = {
[ONYXKEYS.FREQUENTLY_USED_EMOJIS]: OnyxTypes.FrequentlyUsedEmoji[];
[ONYXKEYS.REIMBURSEMENT_ACCOUNT_WORKSPACE_ID]: string;
[ONYXKEYS.IS_LOADING_PAYMENT_METHODS]: boolean;
[ONYXKEYS.IS_LOADING_REPORT_DATA]: boolean;
[ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean;
[ONYXKEYS.APP_PROFILING_IN_PROGRESS]: boolean;
[ONYXKEYS.IS_LOADING_APP]: boolean;
Expand Down
5 changes: 3 additions & 2 deletions src/components/PriorityModeController.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useNavigation} from '@react-navigation/native';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import useReportDataLoading from '@hooks/useReportDataLoading';
import {updateChatPriorityMode} from '@libs/actions/User';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
import Log from '@libs/Log';
Expand All @@ -24,7 +25,7 @@ import FocusModeNotification from './FocusModeNotification';
*/
export default function PriorityModeController() {
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID, canBeMissing: true});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const isLoadingReportData = useReportDataLoading();
const [isInFocusMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {selector: (priorityMode) => priorityMode === CONST.PRIORITY_MODE.GSD, canBeMissing: true});
const [hasTriedFocusMode] = useOnyx(ONYXKEYS.NVP_TRY_FOCUS_MODE, {canBeMissing: true});
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
Expand All @@ -50,7 +51,7 @@ export default function PriorityModeController() {
// Listen for state changes and trigger the #focus mode when appropriate
useEffect(() => {
// Wait for Onyx state to fully load
if (isLoadingReportData !== false || isInFocusMode === undefined || hasTriedFocusMode === undefined || !accountID) {
if (isLoadingReportData || isInFocusMode === undefined || hasTriedFocusMode === undefined || !accountID) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions src/hooks/useCommandsLoading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {useMemo} from 'react';
import ONYXKEYS from '@src/ONYXKEYS';
import useOnyx from './useOnyx';

/**
* Hook that determines if any of the specified commands are currently being processed
*
* Monitors persisted requests queue for the provided commands that are not initiated offline.
*
* @param commands - Array of command strings to monitor
* @returns boolean indicating if any of the specified commands are currently loading
*/
export default function useCommandsLoading(commands: string[]): boolean {
const [req] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {canBeMissing: false});

return useMemo(() => req?.some((request) => commands.includes(request.command) && !request.initiatedOffline) ?? false, [req, commands]);
}
11 changes: 5 additions & 6 deletions src/hooks/useLoadingBarVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import {WRITE_COMMANDS} from '@libs/API/types';
import ONYXKEYS from '@src/ONYXKEYS';

Check failure on line 2 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'ONYXKEYS' is defined but never used

Check failure on line 2 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / ESLint check

'ONYXKEYS' is defined but never used
import useNetwork from './useNetwork';
import useCommandsLoading from './useCommandsLoading';
import useOnyx from './useOnyx';

Check failure on line 5 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'useOnyx' is defined but never used

Check failure on line 5 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / ESLint check

'useOnyx' is defined but never used

// Commands that should trigger the LoadingBar to show
const RELEVANT_COMMANDS = new Set<string>([WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT, WRITE_COMMANDS.READ_NEWEST_ACTION]);

Check failure on line 8 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'RELEVANT_COMMANDS' is assigned a value but never used

Check failure on line 8 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / ESLint check

'RELEVANT_COMMANDS' is assigned a value but never used

/**
* Hook that determines whether LoadingBar should be visible based on active queue requests
* Shows LoadingBar when any of the RELEVANT_COMMANDS are being processed
*
* @returns boolean indicating if the loading bar should be visible
*/
export default function useLoadingBarVisibility(): boolean {
const [persistedRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {canBeMissing: false});
const [ongoingRequests] = useOnyx(ONYXKEYS.PERSISTED_ONGOING_REQUESTS, {canBeMissing: false});
const hasRelevantCommands = useCommandsLoading(LOADING_BAR_COMMANDS);

Check failure on line 17 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe argument of type `any` assigned to a parameter of type `string[]`

Check failure on line 17 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 'LOADING_BAR_COMMANDS'.

Check failure on line 17 in src/hooks/useLoadingBarVisibility.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe argument of type `any` assigned to a parameter of type `string[]`
const {isOffline} = useNetwork();

// Don't show loading bar if currently offline
if (isOffline) {
return false;
}

const hasPersistedRequests = persistedRequests?.some((request) => RELEVANT_COMMANDS.has(request.command) && !request.initiatedOffline) ?? false;
const hasOngoingRequests = !!ongoingRequests && RELEVANT_COMMANDS.has(ongoingRequests?.command);

return hasPersistedRequests || hasOngoingRequests;
return hasRelevantCommands;
}
18 changes: 18 additions & 0 deletions src/hooks/useReportDataLoading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {WRITE_COMMANDS} from '@libs/API/types';
import useCommandsLoading from './useCommandsLoading';

// Commands that should trigger report data loading states
const REPORT_DATA_COMMANDS = [WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT];

/**
* Hook that determines if report data is currently being loaded
*
* Monitors persisted requests queue for OpenApp, ReconnectApp, and OpenReport commands
* that trigger report data fetching from the server. This hook ignores offline state
* and is primarily used for full-screen loading indicators.
*
* @returns boolean indicating if report data is currently loading
*/
export default function useReportDataLoading(): boolean {
return useCommandsLoading(REPORT_DATA_COMMANDS);
}
9 changes: 4 additions & 5 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,22 @@

let allPolicies: OnyxCollection<Policy>;
let activePolicyId: OnyxEntry<string>;
let isLoadingReportData = true;
let hasLoadedApp = false;

Onyx.connect({

Check warning on line 62 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

Onyx.connect({

Check warning on line 68 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyId = value),
});

Onyx.connect({

Check warning on line 73 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
initWithStoredValues: false,
callback: (value) => (isLoadingReportData = value ?? false),
key: ONYXKEYS.HAS_LOADED_APP,
callback: (value) => (hasLoadedApp = value ?? false),
});

/**
Expand Down Expand Up @@ -1300,7 +1299,7 @@
return false;
}

return !isPolicyAccessible(policy) && !isLoadingReportData;
return !isPolicyAccessible(policy) && hasLoadedApp;
}

function hasOtherControlWorkspaces(currentPolicyID: string) {
Expand Down
16 changes: 2 additions & 14 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

let currentUserAccountID: number | undefined;
let currentUserEmail: string;
Onyx.connect({

Check warning on line 46 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserAccountID = val?.accountID;
Expand All @@ -52,14 +52,14 @@
});

let isSidebarLoaded: boolean | undefined;
Onyx.connect({

Check warning on line 55 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.IS_SIDEBAR_LOADED,
callback: (val) => (isSidebarLoaded = val),
initWithStoredValues: false,
});

let preferredLocale: Locale | undefined;
Onyx.connect({

Check warning on line 62 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: (val) => {
if (!val || !isSupportedLocale(val)) {
Expand All @@ -79,7 +79,7 @@
});

let priorityMode: ValueOf<typeof CONST.PRIORITY_MODE> | undefined;
Onyx.connect({

Check warning on line 82 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_PRIORITY_MODE,
callback: (nextPriorityMode) => {
// When someone switches their priority mode we need to fetch all their chats because only #focus mode works with a subset of a user's chats. This is only possible via the OpenApp command.
Expand All @@ -92,7 +92,7 @@
});

let isUsingImportedState: boolean | undefined;
Onyx.connect({

Check warning on line 95 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.IS_USING_IMPORTED_STATE,
callback: (value) => {
isUsingImportedState = value ?? false;
Expand All @@ -100,7 +100,7 @@
});

let preservedUserSession: OnyxTypes.Session | undefined;
Onyx.connect({

Check warning on line 103 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PRESERVED_USER_SESSION,
callback: (value) => {
preservedUserSession = value;
Expand All @@ -108,7 +108,7 @@
});

let preservedShouldUseStagingServer: boolean | undefined;
Onyx.connect({

Check warning on line 111 in src/libs/actions/App.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ACCOUNT,
callback: (value) => {
preservedShouldUseStagingServer = value?.shouldUseStagingServer;
Expand Down Expand Up @@ -264,21 +264,9 @@
*/
function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = false, shouldKeepPublicRooms = false): OnyxData {
const result: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
value: true,
},
],
optimisticData: [],
successData: [],
finallyData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
value: false,
},
],
finallyData: [],
queueFlushedData: [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down
23 changes: 1 addition & 22 deletions src/libs/actions/Welcome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {OnboardingCompanySize} from './OnboardingFlow';

type OnboardingData = Onboarding | undefined;

let isLoadingReportData = true;
let tryNewDotData: TryNewDot | undefined;
let onboarding: OnboardingData;

Expand Down Expand Up @@ -62,17 +61,6 @@ function isOnboardingFlowCompleted({onCompleted, onNotCompleted, onCanceled}: Ha
});
}

/**
* Check if report data are loaded
*/
function checkServerDataReady() {
if (isLoadingReportData) {
return;
}

resolveIsReadyPromise?.();
}

/**
* Check if user completed HybridApp onboarding
*/
Expand All @@ -93,6 +81,7 @@ function checkOnboardingDataReady() {
}

resolveOnboardingFlowStatus();
resolveIsReadyPromise?.();
}

function setOnboardingPurposeSelected(value: OnboardingPurpose) {
Expand Down Expand Up @@ -169,15 +158,6 @@ Onyx.connect({
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
initWithStoredValues: false,
callback: (value) => {
isLoadingReportData = value ?? false;
checkServerDataReady();
},
});

Onyx.connect({
key: ONYXKEYS.NVP_TRY_NEW_DOT,
callback: (value) => {
Expand All @@ -193,7 +173,6 @@ function resetAllChecks() {
isOnboardingFlowStatusKnownPromise = new Promise<void>((resolve) => {
resolveOnboardingFlowStatus = resolve;
});
isLoadingReportData = true;
isOnboardingInProgress = false;
clearInitialPath();
}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/ConciergePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useOnyx} from 'react-native-onyx';
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView';
import ScreenWrapper from '@components/ScreenWrapper';
import useReportDataLoading from '@hooks/useReportDataLoading';
import useThemeStyles from '@hooks/useThemeStyles';
import {confirmReadyToOpenApp} from '@libs/actions/App';
import {navigateToConciergeChat} from '@libs/actions/Report';
Expand All @@ -23,7 +24,7 @@ function ConciergePage() {
const styles = useThemeStyles();
const isUnmounted = useRef(false);
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true, canBeMissing: true});
const isLoadingReportData = useReportDataLoading();
const route = useRoute();

const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
Expand All @@ -35,7 +36,7 @@ function ConciergePage() {
if (session && 'authToken' in session) {
confirmReadyToOpenApp();
Navigation.isNavigationReady().then(() => {
if (isUnmounted.current || isLoadingReportData === undefined || !!isLoadingReportData) {
if (isUnmounted.current || isLoadingReportData) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {useEffect, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useReportDataLoading from '@hooks/useReportDataLoading';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import {openReport} from '@libs/actions/Report';
import getComponentDisplayName from '@libs/getComponentDisplayName';
Expand Down Expand Up @@ -42,7 +43,7 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`, {canBeMissing: true});
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${props.route.params.reportID}`, {canBeMissing: true});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const isLoadingReportData = useReportDataLoading();
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${props.route.params.reportID}`, {canEvict: false, canBeMissing: true});
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/withReportOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {useEffect} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useReportDataLoading from '@hooks/useReportDataLoading';
import {openReport} from '@libs/actions/Report';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
Expand Down Expand Up @@ -67,7 +68,7 @@ export default function (
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${props.route.params.reportID}`, {canBeMissing: true});
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true});
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${props.route.params.reportID}`, {canBeMissing: true});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const isLoadingReportData = useReportDataLoading();
const isFocused = useIsFocused();
const contentShown = React.useRef(false);
const isReportIdInRoute = !!props.route.params.reportID?.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import type {ValidateCodeFormHandle} from '@components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useReportDataLoading from '@hooks/useReportDataLoading';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand Down Expand Up @@ -56,10 +57,10 @@
const [session, sessionResult] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const [myDomainSecurityGroups, myDomainSecurityGroupsResult] = useOnyx(ONYXKEYS.MY_DOMAIN_SECURITY_GROUPS, {canBeMissing: true});
const [securityGroups, securityGroupsResult] = useOnyx(ONYXKEYS.COLLECTION.SECURITY_GROUP, {canBeMissing: true});
const [isLoadingReportData, isLoadingReportDataResult] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true, canBeMissing: true});
const isLoadingReportData = useReportDataLoading();
const [isValidateCodeFormVisible, setIsValidateCodeFormVisible] = useState(true);
const {isActingAsDelegate, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext);
const isLoadingOnyxValues = isLoadingOnyxValue(loginListResult, sessionResult, myDomainSecurityGroupsResult, securityGroupsResult, isLoadingReportDataResult);

Check failure on line 63 in src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe argument of type `any` assigned to a parameter of type `ResultMetadata<unknown>`

Check failure on line 63 in src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 'isLoadingReportDataResult'. Did you mean 'isLoadingReportData'?

Check failure on line 63 in src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe argument of type `any` assigned to a parameter of type `ResultMetadata<unknown>`
const {isAccountLocked, showLockedAccountModal} = useContext(LockedAccountContext);

const {formatPhoneNumber, translate} = useLocalize();
Expand Down
5 changes: 3 additions & 2 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {FullPageNotFoundViewProps} from '@components/BlockingViews/FullPage
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useNetwork from '@hooks/useNetwork';
import useReportDataLoading from '@hooks/useReportDataLoading';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import {openWorkspace} from '@libs/actions/Policy/Policy';
import {isValidMoneyRequestType} from '@libs/IOUUtils';
Expand Down Expand Up @@ -131,7 +132,7 @@ function AccessOrNotFoundWrapper({
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
canBeMissing: true,
});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true, canBeMissing: true});
const isLoadingReportData = useReportDataLoading();
const {login = ''} = useCurrentUserPersonalDetails();
const isPolicyIDInRoute = !!policyID?.length;
const isMoneyRequest = !!iouType && isValidMoneyRequestType(iouType);
Expand All @@ -149,7 +150,7 @@ function AccessOrNotFoundWrapper({
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isPolicyIDInRoute, policyID]);

const shouldShowFullScreenLoadingIndicator = !isMoneyRequest && isLoadingReportData !== false && (!Object.entries(policy ?? {}).length || !policy?.id);
const shouldShowFullScreenLoadingIndicator = !isMoneyRequest && isLoadingReportData && (!Object.entries(policy ?? {}).length || !policy?.id);

const isFeatureEnabled = featureName ? isPolicyFeatureEnabledUtil(policy, featureName) : true;

Expand Down
5 changes: 3 additions & 2 deletions src/pages/workspace/withPolicyAndFullscreenLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {forwardRef} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useReportDataLoading from '@hooks/useReportDataLoading';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList} from '@src/types/onyx';
import type {WithPolicyOnyxProps, WithPolicyProps} from './withPolicy';
Expand Down Expand Up @@ -35,8 +36,8 @@ export default function withPolicyAndFullscreenLoading<TProps extends WithPolicy
}: Omit<TProps, keyof WithPolicyAndFullscreenLoadingOnyxProps>,
ref: ForwardedRef<TRef>,
) {
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true});
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const isLoadingReportData = useReportDataLoading();
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: true});

if ((isLoadingPolicy || isLoadingReportData) && isEmpty(policy) && isEmpty(policyDraft)) {
return <FullscreenLoadingIndicator />;
Expand Down
2 changes: 0 additions & 2 deletions tests/perf-test/SidebarLinks.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ describe('SidebarLinks', () => {
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
...mockedResponseMap,
});

Expand All @@ -108,7 +107,6 @@ describe('SidebarLinks', () => {
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
...mockedResponseMap,
});

Expand Down
2 changes: 0 additions & 2 deletions tests/unit/ReportActionItemSingleTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatch

const ONYXKEYS = {
PERSONAL_DETAILS_LIST: 'personalDetailsList',
IS_LOADING_REPORT_DATA: 'isLoadingReportData',
COLLECTION: {
REPORT_ACTIONS: 'reportActions_',
POLICY: 'policy_',
Expand Down Expand Up @@ -60,7 +59,6 @@ describe('ReportActionItemSingle', () => {
.then(() =>
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: fakePersonalDetails,
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
...policyCollectionDataSet,
}),
)
Expand Down
Loading