Skip to content

Commit 3512d3d

Browse files
authored
Merge pull request #90175 from callstack-internal/fix/search-params-overwrite-v2
Fix navigation arrows disappearing during report browsing - v2
2 parents 9c6befb + 4a51eae commit 3512d3d

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ function MoneyRequestReportNavigationInner({reportID, shouldDisplayNarrowVersion
158158
shouldCalculateTotals: false,
159159
searchKey: lastSearchQuery.searchKey,
160160
isLoading: isSearchLoading,
161+
shouldUpdateLastSearchParams: true,
161162
});
162163
}
163164

src/components/Search/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import useSearchHighlightAndScroll from '@hooks/useSearchHighlightAndScroll';
2727
import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals';
2828
import useThemeStyles from '@hooks/useThemeStyles';
2929
import {turnOffMobileSelectionMode, turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
30+
import {saveLastSearchParams} from '@libs/actions/ReportNavigation';
3031
import type {TransactionPreviewData} from '@libs/actions/Search';
3132
import {setOptimisticDataForTransactionThreadPreview} from '@libs/actions/Search';
3233
import {flushDeferredWrite, getOptimisticWatchKey, hasDeferredWrite} from '@libs/deferredLayoutWrite';
@@ -1207,6 +1208,16 @@ function Search({
12071208
unmarkReportIDAsMultiTransactionExpense(reportID);
12081209
}
12091210

1211+
// Persist the current search context so prev/next navigation arrows
1212+
// in the report RHP can reference the correct result set.
1213+
saveLastSearchParams({
1214+
queryJSON,
1215+
offset,
1216+
searchKey: currentSearchKey,
1217+
hasMoreResults: !!searchResults?.search?.hasMoreResults,
1218+
allowPostSearchRecount: true,
1219+
});
1220+
12101221
requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID, backTo})));
12111222
return;
12121223
}
@@ -1246,6 +1257,10 @@ function Search({
12461257
betas,
12471258
email,
12481259
accountID,
1260+
queryJSON,
1261+
offset,
1262+
searchResults?.search?.hasMoreResults,
1263+
currentSearchKey,
12491264
],
12501265
);
12511266

src/hooks/useSearchPageSetup.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {useFocusEffect} from '@react-navigation/native';
22
import {useEffect} from 'react';
33
import {useSearchActionsContext, useSearchStateContext} from '@components/Search/SearchContext';
44
import type {SearchQueryJSON} from '@components/Search/types';
5+
import {saveLastSearchParams} from '@libs/actions/ReportNavigation';
56
import {openSearch, search} from '@libs/actions/Search';
67
import {hasDeferredWrite} from '@libs/deferredLayoutWrite';
78
import {isSearchDataLoaded} from '@libs/SearchUIUtils';
@@ -10,6 +11,10 @@ import useNetwork from './useNetwork';
1011
import usePrevious from './usePrevious';
1112
import useSearchShouldCalculateTotals from './useSearchShouldCalculateTotals';
1213

14+
// Gates the save below to real hash changes so snapshot-loading re-fires don't wipe fields
15+
// (hasMoreResults, previousLengthOfResults) maintained by report-browsing callers.
16+
let lastSavedSearchHash: number | undefined;
17+
1318
/**
1419
* Handles page-level setup for Search that must happen before the Search component mounts:
1520
* - Clears selected transactions when the query changes
@@ -51,6 +56,14 @@ function useSearchPageSetup(queryJSON: Readonly<SearchQueryJSON> | undefined) {
5156
if (!queryJSON || hash === undefined || shouldUseLiveData || isOffline) {
5257
return;
5358
}
59+
60+
// Must run even on cached snapshots, else SearchTabButton's Onyx fallback restores
61+
// a stale query after a tab switch (e.g. filter reappears after Reset).
62+
if (lastSavedSearchHash !== hash) {
63+
saveLastSearchParams({queryJSON, offset: 0, searchKey: currentSearchKey, hasMoreResults: false, allowPostSearchRecount: false});
64+
lastSavedSearchHash = hash;
65+
}
66+
5467
if (isSnapshotDataLoaded || isSnapshotSearchLoading) {
5568
return;
5669
}

src/libs/actions/Search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ function search({
531531
prevReportsLength,
532532
isOffline = false,
533533
isLoading,
534-
shouldUpdateLastSearchParams = true,
534+
shouldUpdateLastSearchParams = false,
535535
skipWaitForWrites = false,
536536
}: {
537537
queryJSON: Readonly<SearchQueryJSON>;

0 commit comments

Comments
 (0)