diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-04 17:43:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-04 19:09:58 +0900 |
| commit | f8e4be9b36a16969ac53bd9ce12ce8064be10196 (patch) | |
| tree | b2cf350d2e2e52803ff809311effb40da767d859 /src/client/atoms/cards.ts | |
| parent | e1c9e5e89bb91bca2586470c786510c3e1c03826 (diff) | |
| download | kioku-f8e4be9b36a16969ac53bd9ce12ce8064be10196.tar.gz kioku-f8e4be9b36a16969ac53bd9ce12ce8064be10196.tar.zst kioku-f8e4be9b36a16969ac53bd9ce12ce8064be10196.zip | |
refactor(client): migrate state management from React Context to Jotai
Replace AuthProvider and SyncProvider with Jotai atoms for more granular
state management and better performance. This migration:
- Creates atoms for auth, sync, decks, cards, noteTypes, and study state
- Uses atomFamily for parameterized state (e.g., cards by deckId)
- Introduces StoreInitializer component for subscription initialization
- Updates all components and pages to use useAtomValue/useSetAtom
- Updates all tests to use Jotai Provider with createStore pattern
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/client/atoms/cards.ts')
| -rw-r--r-- | src/client/atoms/cards.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/client/atoms/cards.ts b/src/client/atoms/cards.ts new file mode 100644 index 0000000..f053ab9 --- /dev/null +++ b/src/client/atoms/cards.ts @@ -0,0 +1,31 @@ +import { apiClient } from "../api/client"; +import { createReloadableAtomFamily } from "./utils"; + +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 = createReloadableAtomFamily( + async (deckId: string) => { + const res = await apiClient.rpc.api.decks[":deckId"].cards.$get({ + param: { deckId }, + }); + const data = await apiClient.handleResponse<{ cards: Card[] }>(res); + return data.cards; + }, +); |
