blob: 225d78c127440bf18928be6bc4e1290cf64a31cb (
plain)
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
26
27
28
29
30
31
32
33
34
35
|
import { atomFamily } from "jotai-family";
import { atomWithSuspenseQuery } from "jotai-tanstack-query";
import { apiClient } from "../api/client";
export interface Card {
id: string;
deckId: string;
noteId: string;
isReversed: boolean;
front: string;
back: string;
state: number;
due: string;
reps: number;
lapses: number;
createdAt: string;
updatedAt: string;
}
// =====================
// Cards by Deck - Suspense-compatible
// =====================
export const cardsByDeckAtomFamily = atomFamily((deckId: string) =>
atomWithSuspenseQuery(() => ({
queryKey: ["decks", deckId, "cards"],
queryFn: async () => {
const res = await apiClient.rpc.api.decks[":deckId"].cards.$get({
param: { deckId },
});
const data = await apiClient.handleResponse<{ cards: Card[] }>(res);
return data.cards;
},
})),
);
|