Skip to content

Commit

Permalink
useTransactionsSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Oct 31, 2024
1 parent 82c1b92 commit b669447
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useDispatch, useSelector } from 'react-redux';
import { Navigate, useParams, useLocation } from 'react-router-dom';

import { t } from 'i18next';
import { useDebounceCallback } from 'usehooks-ts';
import { v4 as uuidv4 } from 'uuid';

import {
Expand All @@ -32,6 +31,7 @@ import {
import {
usePreviewTransactions,
useTransactions,
useTransactionsSearch,
} from 'loot-core/client/data-hooks/transactions';
import { validForTransfer } from 'loot-core/client/transfer';
import { type UndoState } from 'loot-core/server/undo';
Expand Down Expand Up @@ -275,7 +275,6 @@ function AccountTransactions({
onBatchUnlinkSchedule,
} = useTransactionBatchActions();

const [isSearching, setIsSearching] = useState<boolean>(false);
const [filterConditions, setFilterConditions] = useState<ConditionEntity[]>(
location?.state?.filterConditions || [],
);
Expand Down Expand Up @@ -688,25 +687,11 @@ function AccountTransactions({
}
}, [modalShowing, reloadTransactions, wasModalShowing]);

const updateSearchQuery = useDebounceCallback(
useCallback(
async (searchText: string) => {
if (searchText === '') {
setTransactionsQuery(await rootTransactionsQuery());
} else if (searchText) {
setTransactionsQuery(currentQuery =>
queries.transactionsSearch(currentQuery, searchText, dateFormat),
);
}

setIsSearching(searchText !== '');
},
[rootTransactionsQuery, dateFormat],
),
150,
);

const onSearch = useCallback(updateSearchQuery, [updateSearchQuery]);
const { isSearching, search: onSearch } = useTransactionsSearch({
updateQuery: setTransactionsQuery,
resetQuery: () => rootTransactionsQuery().then(setTransactionsQuery),
dateFormat,
});

const onSync = useCallback(async () => {
const account = accounts.find(acct => acct.id === accountId);
Expand Down

0 comments on commit b669447

Please sign in to comment.