Skip to content

Commit

Permalink
reset selected transaction if getting new updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cretadn22 committed Oct 3, 2024
1 parent 66d1025 commit f8769d8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Property 'transactions' does not exist on type 'ReportActionListItemType | TransactionListItemType | ReportListItemType'.

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Parameter 'transaction' implicitly has an 'any' type.

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe call of an `any` typed value

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .forEach on an `error` typed value

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Prefer an early return to a conditionally-wrapped function body

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe call of an `any` typed value

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .forEach on an `error` typed value

Check failure on line 193 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer an early return to a conditionally-wrapped function body
if (Object.keys(selectedTransactions).includes(transaction.transactionID)) {

Check failure on line 194 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 194 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .transactionID on an `any` value

Check failure on line 194 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 194 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .transactionID on an `any` value
newTransactionList[transaction.transactionID] = {

Check failure on line 195 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Computed name [transaction.transactionID] resolves to an `any` value

Check failure on line 195 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .transactionID on an `any` value

Check failure on line 195 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Computed name [transaction.transactionID] resolves to an `any` value

Check failure on line 195 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .transactionID on an `any` value
action: transaction.action,

Check failure on line 196 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe assignment of an `any` value

Check failure on line 196 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .action on an `any` value

Check failure on line 196 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe assignment of an `any` value

Check failure on line 196 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .action on an `any` value
canHold: transaction.canHold,

Check failure on line 197 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe assignment of an `any` value

Check failure on line 197 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe assignment of an `any` value
canUnhold: transaction.canUnhold,
isSelected: selectedTransactions[transaction.transactionID].isSelected,
canDelete: transaction.canDelete,
}
}
})
})
setSelectedTransactions(newTransactionList, data);
}, [data])

Check warning on line 206 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useEffect has missing dependencies: 'selectedTransactions' and 'setSelectedTransactions'. Either include them or remove the dependency array

Check warning on line 206 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useEffect has missing dependencies: 'selectedTransactions' and 'setSelectedTransactions'. Either include them or remove the dependency array

useEffect(() => {
if (!isSearchResultsEmpty || prevIsSearchResultEmpty) {
return;
Expand All @@ -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}`;
Expand Down

0 comments on commit f8769d8

Please sign in to comment.