From 7ca9941982a7d7a4c126d215770ce71ad2f7f427 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Sat, 2 May 2026 11:11:53 +0900
Subject: 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.
---
 src/client/components/ImportNotesModal.tsx | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'src/client/components/ImportNotesModal.tsx')

diff --git a/src/client/components/ImportNotesModal.tsx b/src/client/components/ImportNotesModal.tsx
index d3a2c0c..a38ac8f 100644
--- a/src/client/components/ImportNotesModal.tsx
+++ b/src/client/components/ImportNotesModal.tsx
@@ -5,8 +5,10 @@ import {
 	faSpinner,
 } from "@fortawesome/free-solid-svg-icons";
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { useAtomValue } from "jotai";
 import { type ChangeEvent, useCallback, useEffect, useState } from "react";
 import { ApiClientError, apiClient } from "../api";
+import { isOnlineAtom } from "../atoms";
 import { parseCSV } from "../utils/csvParser";
 
 interface NoteField {
@@ -64,6 +66,7 @@ export function ImportNotesModal({
 }: ImportNotesModalProps) {
 	const [phase, setPhase] = useState<ImportPhase>("upload");
 	const [error, setError] = useState<string | null>(null);
+	const isOnline = useAtomValue(isOnlineAtom);
 	const [noteTypes, setNoteTypes] = useState<NoteType[]>([]);
 	const [validatedRows, setValidatedRows] = useState<ValidatedRow[]>([]);
 	const [validationErrors, setValidationErrors] = useState<ValidationError[]>(
@@ -490,7 +493,8 @@ export function ImportNotesModal({
 								<button
 									type="button"
 									onClick={handleImport}
-									disabled={validatedRows.length === 0}
+									disabled={validatedRows.length === 0 || !isOnline}
+									title={!isOnline ? "Reconnect to import notes" : undefined}
 									className="px-4 py-2 bg-primary hover:bg-primary-dark text-white font-medium rounded-lg transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed"
 								>
 									Import {validatedRows.length} Note(s)
-- 
cgit v1.3.1

