|
1 | 1 | import {WRITE_COMMANDS} from '@libs/API/types'; |
2 | | -import ONYXKEYS from '@src/ONYXKEYS'; |
3 | | -import useOnyx from './useOnyx'; |
| 2 | +import useCommandsLoading from './useCommandsLoading'; |
4 | 3 |
|
5 | | -// Commands that should trigger loading states |
6 | | -const RELEVANT_COMMANDS = new Set<string>([WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT]); |
| 4 | +// Commands that should trigger report data loading states |
| 5 | +const REPORT_DATA_COMMANDS = [WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT]; |
7 | 6 |
|
8 | 7 | /** |
9 | 8 | * Hook that determines if report data is currently being loaded |
10 | 9 | * |
11 | 10 | * Monitors persisted requests queue for OpenApp, ReconnectApp, and OpenReport commands |
12 | | - * that trigger report data fetching from the server. |
| 11 | + * that trigger report data fetching from the server. This hook ignores offline state |
| 12 | + * and is primarily used for full-screen loading indicators. |
13 | 13 | * |
14 | | - * @param respectOfflineState - If true (default), won't show loading when offline (for loading bars). |
15 | | - * If false, shows loading regardless of offline state (for full-screen loading). |
| 14 | + * @returns boolean indicating if report data is currently loading |
16 | 15 | */ |
17 | | -export default function useReportDataLoading(respectOfflineState = true): boolean { |
18 | | - const [req] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {canBeMissing: false}); |
19 | | - const [network] = useOnyx(ONYXKEYS.NETWORK, {canBeMissing: false}); |
20 | | - |
21 | | - const hasRelevantRequests = req?.some((request) => RELEVANT_COMMANDS.has(request.command) && !request.initiatedOffline) ?? false; |
22 | | - |
23 | | - // For loading bars, respect offline state (don't show when offline) |
24 | | - // For full-screen loading, ignore offline state |
25 | | - if (respectOfflineState && network?.isOffline) { |
26 | | - return false; |
27 | | - } |
28 | | - |
29 | | - return hasRelevantRequests; |
| 16 | +export default function useReportDataLoading(): boolean { |
| 17 | + return useCommandsLoading(REPORT_DATA_COMMANDS); |
30 | 18 | } |
0 commit comments