diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index e459be1815bc..97f58dc8624a 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -180,12 +180,31 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; const isSearchResultsEmpty = !searchResults?.data || SearchUtils.isSearchResultsEmpty(searchResults); const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty); + const data = searchResults === undefined ? [] : SearchUtils.getSections(type, status, searchResults.data, searchResults.search); useEffect(() => { /** We only want to display the skeleton for the status filters the first time we load them for a specific data type */ setShouldShowStatusBarLoading(shouldShowLoadingState && searchResults?.search?.type !== type); }, [searchResults?.search?.type, setShouldShowStatusBarLoading, shouldShowLoadingState, type]); + useEffect(() => { + const newTransactionList: SelectedTransactions = {}; + data.forEach((report) => { + report?.transactions?.forEach((transaction) => { + if (Object.keys(selectedTransactions).includes(transaction.transactionID)) { + newTransactionList[transaction.transactionID] = { + action: transaction.action, + canHold: transaction.canHold, + canUnhold: transaction.canUnhold, + isSelected: selectedTransactions[transaction.transactionID].isSelected, + canDelete: transaction.canDelete, + } + } + }) + }) + setSelectedTransactions(newTransactionList, data); + }, [data]) + useEffect(() => { if (!isSearchResultsEmpty || prevIsSearchResultEmpty) { return; @@ -208,7 +227,6 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr } const ListItem = SearchUtils.getListItem(type, status); - const data = SearchUtils.getSections(type, status, searchResults.data, searchResults.search); const sortedData = SearchUtils.getSortedSections(type, status, data, sortBy, sortOrder); const sortedSelectedData = sortedData.map((item) => { const baseKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${(item as TransactionListItemType).transactionID}`;