(filters?: InfiniteChatsFilters)
| 565 | }; |
| 566 | |
| 567 | export const infiniteChats = (filters?: InfiniteChatsFilters) => { |
| 568 | const limit = DEFAULT_CHAT_PAGE_LIMIT; |
| 569 | const q = getInfiniteChatsQueryString(filters); |
| 570 | |
| 571 | return { |
| 572 | queryKey: infiniteChatsKey(filters), |
| 573 | getNextPageParam: (lastPage: TypesGen.Chat[], pages: TypesGen.Chat[][]) => { |
| 574 | if (lastPage.length < limit) { |
| 575 | return undefined; |
| 576 | } |
| 577 | return pages.length + 1; |
| 578 | }, |
| 579 | initialPageParam: 0, |
| 580 | queryFn: ({ pageParam }: { pageParam: unknown }) => { |
| 581 | if (typeof pageParam !== "number") { |
| 582 | throw new Error("pageParam must be a number"); |
| 583 | } |
| 584 | return API.experimental.getChats({ |
| 585 | limit, |
| 586 | offset: pageParam <= 0 ? 0 : (pageParam - 1) * limit, |
| 587 | q, |
| 588 | }); |
| 589 | }, |
| 590 | refetchOnWindowFocus: true as const, |
| 591 | retry: 3, |
| 592 | } satisfies UseInfiniteQueryOptions<TypesGen.Chat[]>; |
| 593 | }; |
| 594 | |
| 595 | export const chatSearch = (q: string) => |
| 596 | queryOptions({ |
no test coverage detected