From c37029a890a525a81891484957eb385351688068 Mon Sep 17 00:00:00 2001 From: Elijah Date: Sun, 28 Jun 2026 10:52:18 -0700 Subject: [PATCH] feat: Add visual success/error states to save instructions button --- src/components/import/GenerateTab.tsx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/import/GenerateTab.tsx b/src/components/import/GenerateTab.tsx index 5b42b14..c2f58eb 100644 --- a/src/components/import/GenerateTab.tsx +++ b/src/components/import/GenerateTab.tsx @@ -6,6 +6,7 @@ export function GenerateTab({ importType }: { importType: "flashcards" | "quizze const [instructions, setInstructions] = useState(""); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); + const [saveResult, setSaveResult] = useState<"success" | "error" | null>(null); const [copied, setCopied] = useState(false); useEffect(() => { @@ -17,14 +18,20 @@ export function GenerateTab({ importType }: { importType: "flashcards" | "quizze async function handleSave() { setSaving(true); + setSaveResult(null); try { - await fetch(`/api/settings/llm-instructions?type=${importType}`, { + const res = await fetch(`/api/settings/llm-instructions?type=${importType}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ value: instructions }), }); + if (!res.ok) throw new Error("Failed to save"); + setSaveResult("success"); + } catch { + setSaveResult("error"); } finally { setSaving(false); + setTimeout(() => setSaveResult(null), 2500); } } @@ -91,9 +98,23 @@ export function GenerateTab({ importType }: { importType: "flashcards" | "quizze