Open History to see the last commit
1import { and, eq, gte, lte, useLiveQuery } from '@tanstack/react-db'
2import ordersCollection from './ordersCollection'
3import type { OrdersSearch } from './types'
4
5function useOrdersQuery(search: OrdersSearch) {
6 return useLiveQuery(
7 (query) =>
8 query
9 .from({ order: ordersCollection })
10 .where(({ order }) =>
11 and(
12 eq(order.status, search.status ?? order.status),
13 eq(
14 order.paymentMethod,
15 search.paymentMethod ?? order.paymentMethod,
16 ),
17 gte(order.from, search.from ?? order.from),
18 lte(order.to, search.to ?? order.to),
19 ),
20 ),
21 [search.paymentMethod, search.status, search.from, search.to],
22 )
23}
24
25export default useOrdersQuery