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
3 changes: 0 additions & 3 deletions config/eslint/eslint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@
"../../src/components/MoneyRequestConfirmationListFooter/hooks/useReceiptThumbnailSource.ts" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/MoneyRequestConfirmationListFooter/sections/DistanceMapSection.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/MoneyRequestConfirmationListFooter/sections/ReceiptSection.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx" "react-hooks/refs" 3
"../../src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx" "react-hooks/set-state-in-effect" 3
"../../src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/components/MoneyRequestReportView/MoneyRequestViewReportFields.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
Expand Down
761 changes: 135 additions & 626 deletions src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import ScrollView from '@components/ScrollView';

import useThemeStyles from '@hooks/useThemeStyles';

import type * as OnyxTypes from '@src/types/onyx';

import type {LayoutChangeEvent} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';

import React from 'react';

import MoneyRequestViewReportFields from './MoneyRequestViewReportFields';
import SearchMoneyRequestReportEmptyState from './SearchMoneyRequestReportEmptyState';

type MoneyRequestReportEmptyStateViewProps = {
/** The empty money request report */
report: OnyxTypes.Report;

/** The workspace the report belongs to */
policy: OnyxEntry<OnyxTypes.Policy>;

/** Callback executed on layout */
onLayout?: (event: LayoutChangeEvent) => void;
};

/** Rendered instead of the unified list when the report has no transactions and no comments. */
function MoneyRequestReportEmptyStateView({report, policy, onLayout}: MoneyRequestReportEmptyStateViewProps) {
const styles = useThemeStyles();

return (
<ScrollView contentContainerStyle={styles.flexGrow1}>
<MoneyRequestViewReportFields
report={report}
policy={policy}
/>
<SearchMoneyRequestReportEmptyState
report={report}
onLayout={onLayout}
policy={policy}
/>
</ScrollView>
);
}

export default MoneyRequestReportEmptyStateView;
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import useLoadReportActions from '@hooks/useLoadReportActions';

import TransitionTracker from '@libs/Navigation/TransitionTracker';
import {isMoneyRequestAction} from '@libs/ReportActionsUtils';

import isSearchTopmostFullScreenRoute from '@navigation/helpers/isSearchTopmostFullScreenRoute';

import {getOlderActions} from '@userActions/Report';

import type * as OnyxTypes from '@src/types/onyx';

import {useEffect, useRef} from 'react';

// The server page size for report actions is ~50. Gaps from IOU prioritization only happen
// when the initial load is truncated, so skip backfill for smaller reports.
const BACKFILL_MIN_ACTIONS_THRESHOLD = 50;

type UseMoneyRequestReportPaginationParams = {
/** The report whose actions are being paginated */
reportID: string | undefined;

/** Paginated report actions, newest-first */
reportActions: OnyxTypes.ReportAction[];

/** IDs of all paginated report actions */
reportActionIDs: string[];

/** The single-transaction thread report ID, when one exists */
transactionThreadReportID: string | undefined;

/** Whether older actions exist beyond the loaded page */
hasOlderActions: boolean;

/** Whether newer actions exist beyond the loaded page */
hasNewerActions: boolean;

/** Whether the network is offline */
isOffline: boolean;

/** The report's pagination cursor state */
reportPaginationState: OnyxTypes.ReportPaginationState | undefined;

/** The report's loading state */
reportLoadingState: OnyxTypes.ReportLoadingState | undefined;
};

type UseMoneyRequestReportPaginationResult = {
/** FlashList onStartReached handler — loads older actions */
onStartReached: () => void;

/** FlashList onEndReached handler — loads newer actions */
onEndReached: () => void;
};

/**
* Owns loading more actions for the money-request report view: the list-edge handlers, the
* auto-load-newer loop, and the IOU backfill loop.
*
* The consuming component remounts per report (keyed by reportID), so the cursor refs below reset
* naturally on report switch and never need render-phase resets.
*/
function useMoneyRequestReportPagination({
reportID,
reportActions,
reportActionIDs,
transactionThreadReportID,
hasOlderActions,
hasNewerActions,
isOffline,
reportPaginationState,
reportLoadingState,
}: UseMoneyRequestReportPaginationParams): UseMoneyRequestReportPaginationResult {
const {loadOlderChats, loadNewerChats} = useLoadReportActions({
reportID,
reportActions,
allReportActionIDs: reportActionIDs,
transactionThreadReportID,
hasOlderActions,
hasNewerActions,
newestFetchedReportActionID: reportPaginationState?.newestFetchedReportActionID,
});

const hasFinishedInitialLoad = reportLoadingState?.isLoadingInitialReportActions === false;
const prevNewestFetchedIDRef = useRef<string | undefined>(undefined);
useEffect(() => {
if (!hasFinishedInitialLoad || !hasNewerActions || reportActions.length === 0 || isOffline || reportLoadingState?.isLoadingNewerReportActions) {
return;
}
// Safety guard: if the cursor hasn't advanced since the last call, the server
// isn't returning new data. Stop to prevent an infinite request loop.
const currentCursor = reportPaginationState?.newestFetchedReportActionID;
if (prevNewestFetchedIDRef.current !== undefined && prevNewestFetchedIDRef.current === currentCursor) {
return;
}
prevNewestFetchedIDRef.current = currentCursor;
loadNewerChats(false);
}, [
hasFinishedInitialLoad,
reportActions.length,
hasNewerActions,
isOffline,
reportLoadingState?.isLoadingNewerReportActions,
reportPaginationState?.newestFetchedReportActionID,
loadNewerChats,
]);

// Backfill loop: the backend prioritizes IOU actions in OpenReport/GetNewerActions for money
// request reports, which can leave non-IOU chat messages in a gap between the IOU-biased cursor
// and older messages. After auto-pagination finishes, walk backwards from the IOU cursor using
// getOlderActions. Each response advances oldestFetchedReportActionID so the next call picks up
// where the previous one left off, until the cursor stops advancing (gap filled).
const prevBackfillCursorRef = useRef<string | undefined>(undefined);
const isBackfillingRef = useRef(false);
useEffect(() => {
if (!hasFinishedInitialLoad || isOffline || hasNewerActions || reportLoadingState?.isLoadingNewerReportActions || reportLoadingState?.isLoadingOlderReportActions) {
return;
}

if (!isBackfillingRef.current) {
const hasIOUActions = reportActions.some((action) => isMoneyRequestAction(action));
if (!hasIOUActions || reportActions.length < BACKFILL_MIN_ACTIONS_THRESHOLD || !reportPaginationState?.newestFetchedReportActionID) {
return;
}
}

const cursor = isBackfillingRef.current ? reportPaginationState?.oldestFetchedReportActionID : reportPaginationState?.newestFetchedReportActionID;
if (!cursor) {
return;
}

if (prevBackfillCursorRef.current === cursor) {
return;
}

isBackfillingRef.current = true;
prevBackfillCursorRef.current = cursor;
const handle = TransitionTracker.runAfterTransitions({callback: () => getOlderActions(reportID, cursor)});

return () => handle.cancel();
}, [
hasFinishedInitialLoad,
isOffline,
hasNewerActions,
reportLoadingState?.isLoadingNewerReportActions,
reportLoadingState?.isLoadingOlderReportActions,
reportPaginationState?.newestFetchedReportActionID,
reportPaginationState?.oldestFetchedReportActionID,
reportActions,
reportID,
]);

const onStartReached = () => {
if (!isSearchTopmostFullScreenRoute()) {
loadOlderChats(false);
return;
}
TransitionTracker.runAfterTransitions({
callback: () => loadOlderChats(false),
});
};

const onEndReached = () => {
loadNewerChats(false);
};

return {onStartReached, onEndReached};
}

export default useMoneyRequestReportPagination;
Loading
Loading