Open History to see the last commit
1import { createCollection } from "@tanstack/db";
2import { queryCollectionOptions } from "@tanstack/query-db-collection";
3import type { BoardRecord } from "@/db/schema";
4import * as TanstackQuery from "@/integrations/tanstack-query/root-provider";
5
6async function getBoards() {
7 const res = await fetch("/api/boards");
8
9 if (!res.ok) {
10 throw new Error("Failed to fetch boards");
11 }
12
13 const data = await res.json();
14 return data as BoardRecord[];
15}
16
17export const boardCollection = createCollection(
18 queryCollectionOptions({
19 queryKey: ["boards"],
20 queryFn: getBoards,
21 queryClient: TanstackQuery.getContext().queryClient,
22 getKey: (item) => item.id,
23 }),
24);