diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-02 10:41:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-02 10:41:12 +0900 |
| commit | 8f1a08fefee3a8e928baec741c830a88a4cd7200 (patch) | |
| tree | 19101c992c19e283e4fa30abafcd58cfeb401cc9 /src/client/atoms/study.ts | |
| parent | 90b06b22e1e468cd19358536919a38ab6377fd23 (diff) | |
| download | kioku-8f1a08fefee3a8e928baec741c830a88a4cd7200.tar.gz kioku-8f1a08fefee3a8e928baec741c830a88a4cd7200.tar.zst kioku-8f1a08fefee3a8e928baec741c830a88a4cd7200.zip | |
feat(study): submit reviews offline via IndexedDB
Move FSRS scheduling to a shared module so the client can compute next
card state without contacting the server. StudyPage now writes the
updated card and review log straight to IndexedDB and lets the existing
sync engine push them on reconnect, instead of POSTing to
/api/decks/:deckId/study/:cardId. Online sessions still trigger a sync
immediately so server-side aggregates stay fresh; offline sessions
accumulate in pendingCountAtom until the next online tick.
The legacy study POST route is preserved for backwards compatibility.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/client/atoms/study.ts')
| -rw-r--r-- | src/client/atoms/study.ts | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/client/atoms/study.ts b/src/client/atoms/study.ts index 73966fd..17519de 100644 --- a/src/client/atoms/study.ts +++ b/src/client/atoms/study.ts @@ -3,21 +3,11 @@ import { atomWithSuspenseQuery } from "jotai-tanstack-query"; import { getStartOfStudyDayBoundary } from "../../shared/date"; import { apiClient } from "../api/client"; import type { CardStateType } from "../db"; +import { cacheStudyCards, type ServerStudyCard } from "../sync"; import { createSeededRandom, shuffle } from "../utils/random"; -export interface StudyCard { - id: string; - deckId: string; - noteId: string; - isReversed: boolean; - front: string; - back: string; +export interface StudyCard extends ServerStudyCard { state: CardStateType; - due: string; - stability: number; - difficulty: number; - reps: number; - lapses: number; noteType: { frontTemplate: string; backTemplate: string; @@ -56,6 +46,9 @@ export const studyDataAtomFamily = atomFamily((deckId: string) => cards: StudyCard[]; }>(cardsRes); + // Cache cards in IndexedDB so reviews can be submitted offline. + await cacheStudyCards(cardsData.cards); + const seed = getStartOfStudyDayBoundary().getTime(); return { deck: deckData.deck, |
