|
1 | | -import type {OnyxCollection} from 'react-native-onyx'; |
2 | 1 | import {isArchivedReport} from '@libs/ReportUtils'; |
3 | 2 | import type {ArchivedReportsIDSet} from '@libs/SearchUIUtils'; |
4 | | -import CONST from '@src/CONST'; |
5 | 3 | import ONYXKEYS from '@src/ONYXKEYS'; |
6 | | -import type {ReportNameValuePairs} from '@src/types/onyx'; |
7 | 4 | import useOnyx from './useOnyx'; |
8 | 5 |
|
9 | | -/** |
10 | | - * Selector that extracts archived report IDs as a sorted array. |
11 | | - * Onyx performs shallow comparison on the returned array to prevent |
12 | | - * unnecessary re-renders without expensive deep comparison of Sets. |
13 | | - */ |
14 | | -const archivedReportIdsSelector = (reportNameValuePairs: OnyxCollection<ReportNameValuePairs>): string[] => { |
15 | | - if (!reportNameValuePairs) { |
16 | | - return []; |
17 | | - } |
18 | | - const ids: string[] = []; |
19 | | - for (const [key, value] of Object.entries(reportNameValuePairs)) { |
20 | | - if (isArchivedReport(value)) { |
21 | | - ids.push(key); |
22 | | - } |
23 | | - } |
24 | | - return ids; |
25 | | -}; |
26 | | - |
27 | 6 | /** |
28 | 7 | * Hook that returns a Set of archived report IDs |
29 | 8 | */ |
30 | 9 | function useArchivedReportsIdSet(): ArchivedReportsIDSet { |
31 | | - const [archivedReportIds = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {selector: archivedReportIdsSelector}); |
| 10 | + const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS); |
| 11 | + const ids: string[] = []; |
32 | 12 |
|
33 | | - return new Set(archivedReportIds); |
| 13 | + if (reportNameValuePairs) { |
| 14 | + for (const [key, value] of Object.entries(reportNameValuePairs)) { |
| 15 | + if (isArchivedReport(value)) { |
| 16 | + ids.push(key); |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + return new Set(ids); |
34 | 21 | } |
35 | 22 |
|
36 | 23 | export default useArchivedReportsIdSet; |
0 commit comments