forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-options.ts
More file actions
25 lines (22 loc) · 940 Bytes
/
query-options.ts
File metadata and controls
25 lines (22 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// src/lib/query-options.ts
//
// Shared TanStack Query options for endpoints with multiple consumers.
// Each consumer subscribes to the shared cache via `select`.
import { queryOptions } from "@tanstack/react-query"
import type { SafeDownloadClient, TrackerSummary } from "@/types/api"
export const clientQueryOptions = queryOptions({
queryKey: ["clients"] as const,
queryFn: async ({ signal }) => {
const res = await fetch("/api/clients", { signal: signal ?? AbortSignal.timeout(15_000) })
if (!res.ok) return [] as SafeDownloadClient[]
return res.json() as Promise<SafeDownloadClient[]>
},
})
export const trackerQueryOptions = queryOptions({
queryKey: ["trackers"] as const,
queryFn: async ({ signal }) => {
const res = await fetch("/api/trackers", { signal: signal ?? AbortSignal.timeout(15_000) })
if (!res.ok) return [] as TrackerSummary[]
return res.json() as Promise<TrackerSummary[]>
},
})