aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/sync/scheduler.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-02 11:11:53 +0900
committernsfisis <nsfisis@gmail.com>2026-05-02 11:12:00 +0900
commit7ca9941982a7d7a4c126d215770ce71ad2f7f427 (patch)
tree0178b48094e9b7b143fd47c4d8479d3d588bb1d7 /src/client/sync/scheduler.ts
parent8f1a08fefee3a8e928baec741c830a88a4cd7200 (diff)
downloadkioku-7ca9941982a7d7a4c126d215770ce71ad2f7f427.tar.gz
kioku-7ca9941982a7d7a4c126d215770ce71ad2f7f427.tar.zst
kioku-7ca9941982a7d7a4c126d215770ce71ad2f7f427.zip
feat(client): read decks/cards/study from IndexedDB first
Switch deckAtom, cardsByDeckAtomFamily, noteTypesAtom, and studyDataAtom to a stale-while-revalidate pattern: read from IndexedDB synchronously, trigger sync in the background, and refetch on sync_complete. When local is empty, await a single bootstrap pull before deciding there's no data. Add study-builder to assemble StudyCards from LocalCard + Note + NoteType + field values, replacing the server /study endpoint dependency. The study session can now run end-to-end offline. Disable submit on all write modals when offline since writes still require the server. Add a "Showing cached data" hint to the sync status indicator. Drop cacheStudyCards (cards arrive via regular sync pull now) and update page tests to reflect that lists no longer refresh by hitting the GET API.
Diffstat (limited to 'src/client/sync/scheduler.ts')
-rw-r--r--src/client/sync/scheduler.ts65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/client/sync/scheduler.ts b/src/client/sync/scheduler.ts
index 72a6e25..9c8572a 100644
--- a/src/client/sync/scheduler.ts
+++ b/src/client/sync/scheduler.ts
@@ -88,68 +88,3 @@ export async function undoReviewLocal(params: {
await localReviewLogRepository.delete(params.reviewLogId);
await syncQueue.notifyChanged();
}
-
-/**
- * Server-shaped study card. Includes all FSRS fields needed to reconstruct
- * a LocalCard so we can submit reviews offline.
- */
-export interface ServerStudyCard {
- id: string;
- deckId: string;
- noteId: string;
- isReversed: boolean;
- front: string;
- back: string;
- state: number;
- due: string;
- stability: number;
- difficulty: number;
- elapsedDays: number;
- scheduledDays: number;
- reps: number;
- lapses: number;
- lastReview: string | null;
- createdAt: string;
- updatedAt: string;
- deletedAt: string | null;
- syncVersion: number;
-}
-
-/**
- * Cache study cards into IndexedDB so the scheduler can submit reviews
- * even when the network drops mid-session. Only cards are cached here —
- * note types / fields / values come through the regular sync pull.
- */
-export async function cacheStudyCards(cards: ServerStudyCard[]): Promise<void> {
- for (const c of cards) {
- const local: LocalCard = {
- id: c.id,
- deckId: c.deckId,
- noteId: c.noteId,
- isReversed: c.isReversed,
- front: c.front,
- back: c.back,
- state: c.state as LocalCard["state"],
- due: new Date(c.due),
- stability: c.stability,
- difficulty: c.difficulty,
- elapsedDays: c.elapsedDays,
- scheduledDays: c.scheduledDays,
- reps: c.reps,
- lapses: c.lapses,
- lastReview: c.lastReview ? new Date(c.lastReview) : null,
- createdAt: new Date(c.createdAt),
- updatedAt: new Date(c.updatedAt),
- deletedAt: c.deletedAt ? new Date(c.deletedAt) : null,
- syncVersion: c.syncVersion,
- _synced: true,
- };
-
- // Don't clobber pending local edits (e.g., a review that hasn't
- // been pushed yet). If the local copy has unsynced changes, skip.
- const existing = await localCardRepository.findById(c.id);
- if (existing && !existing._synced) continue;
-
- await localCardRepository.upsertFromServer(local);
- }
-}