Skip to content

Commit 94cc3e5

Browse files
committed
use selectors instead of hooks
1 parent 871a001 commit 94cc3e5

9 files changed

Lines changed: 167 additions & 589 deletions

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable rulesdir/prefer-early-return */
22
import {useIsFocused, useRoute} from '@react-navigation/native';
3+
import {stableReportSelector} from '@selectors/Report';
34
import isEmpty from 'lodash/isEmpty';
45
import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
56
import type {LayoutChangeEvent, ListRenderItemInfo, NativeScrollEvent, NativeSyntheticEvent} from 'react-native';
@@ -22,7 +23,6 @@ import useReportScrollManager from '@hooks/useReportScrollManager';
2223
import useReportTransactionsCollection from '@hooks/useReportTransactionsCollection';
2324
import useResponsiveLayoutOnWideRHP from '@hooks/useResponsiveLayoutOnWideRHP';
2425
import useScrollToEndOnNewMessageReceived from '@hooks/useScrollToEndOnNewMessageReceived';
25-
import useStableReportForReportActionItem from '@hooks/useStableReportForReportActionItem';
2626
import useThemeStyles from '@hooks/useThemeStyles';
2727
import useWindowDimensions from '@hooks/useWindowDimensions';
2828
import {isConsecutiveChronosAutomaticTimerAction} from '@libs/ChronosUtils';
@@ -101,7 +101,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
101101
// Self-subscribe to report, policy, metadata, actions, transactions
102102
// report is guaranteed to exist — callers only render this component when report is loaded
103103
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`) as unknown as [OnyxTypes.Report];
104-
const reportStable = useStableReportForReportActionItem(report);
104+
const [reportStable] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {selector: stableReportSelector});
105105
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(report?.policyID)}`);
106106
const [reportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${reportIDFromRoute}`);
107107
const [reportPaginationState] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_PAGINATION_STATE}${reportIDFromRoute}`);

src/hooks/useStableReportActionForReportActionItem.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/hooks/useStableReportForReportActionItem.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/pages/inbox/report/ReportActionItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {stableReportSelector} from '@selectors/Report';
12
import React, {useCallback} from 'react';
23
import type {OnyxEntry} from 'react-native-onyx';
34
import useOnyx from '@hooks/useOnyx';
@@ -26,7 +27,7 @@ function ReportActionItem({action, report, draftMessage, personalDetails, linked
2627
const reportID = report?.reportID;
2728
const originalReportID = useOriginalReportID(reportID, action);
2829
const isOriginalReportArchived = useReportIsArchived(originalReportID);
29-
const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`);
30+
const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, {selector: stableReportSelector});
3031
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getIOUReportIDFromReportActionPreview(action)}`);
3132

3233
const transactionsOnIOUReport = useReportTransactions(iouReport?.reportID);

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {useIsFocused, useRoute} from '@react-navigation/native';
2+
import {stableReportSelector} from '@selectors/Report';
23
import type {ListRenderItemInfo} from '@shopify/flash-list';
34
import React, {memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
45
import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent} from 'react-native';
@@ -20,7 +21,6 @@ import useReportIsArchived from '@hooks/useReportIsArchived';
2021
import useReportScrollManager from '@hooks/useReportScrollManager';
2122
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2223
import useScrollToEndOnNewMessageReceived from '@hooks/useScrollToEndOnNewMessageReceived';
23-
import useStableReportForReportActionItem from '@hooks/useStableReportForReportActionItem';
2424
import useStyleUtils from '@hooks/useStyleUtils';
2525
import useThemeStyles from '@hooks/useThemeStyles';
2626
import useWindowDimensions from '@hooks/useWindowDimensions';
@@ -220,7 +220,7 @@ function ReportActionsList({
220220
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`);
221221
const isHarvestCreatedExpenseReportAction = isHarvestCreatedExpenseReport(reportNameValuePairs?.origin, reportNameValuePairs?.originalID);
222222

223-
const reportStable = useStableReportForReportActionItem(report) ?? report;
223+
const [reportStable = report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, {selector: stableReportSelector});
224224

225225
const backTo = route?.params?.backTo as string;
226226
const linkedReportActionID = route?.params?.reportActionID;
@@ -348,6 +348,7 @@ function ReportActionsList({
348348
visibleReportActionsWithDraft.push(draftReportAction);
349349
return visibleReportActionsWithDraft;
350350
}, [draftReportAction, sortedVisibleReportActions]);
351+
351352
const draftMessageHTML = draftReportAction ? getReportActionMessage(draftReportAction)?.html : undefined;
352353
const isSyntheticDraftVisible = !!draftReportAction && renderedVisibleReportActions !== sortedVisibleReportActions;
353354
const draftAutoScrollKey = isSyntheticDraftVisible ? `${draftReportAction.reportActionID}:${draftMessageHTML ?? ''}` : '';

0 commit comments

Comments
 (0)