blob: 57abef42ee221bad08254969406956d74e19a988 (
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
36
37
|
import { apiClient } from "../api/client";
import { createReloadableAtom, createReloadableAtomFamily } from "./utils";
export interface Deck {
id: string;
name: string;
description: string | null;
newCardsPerDay: number;
createdAt: string;
updatedAt: string;
}
// =====================
// Decks List - Suspense-compatible
// =====================
export const decksAtom = createReloadableAtom(async () => {
const res = await apiClient.rpc.api.decks.$get(undefined, {
headers: apiClient.getAuthHeader(),
});
const data = await apiClient.handleResponse<{ decks: Deck[] }>(res);
return data.decks;
});
// =====================
// Single Deck by ID - Suspense-compatible
// =====================
export const deckByIdAtomFamily = createReloadableAtomFamily(
async (deckId: string) => {
const res = await apiClient.rpc.api.decks[":id"].$get({
param: { id: deckId },
});
const data = await apiClient.handleResponse<{ deck: Deck }>(res);
return data.deck;
},
);
|