diff --git a/README.md b/README.md index 094e912..c857ea8 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,10 @@ no database, no data leaving your machine except the requests you send to Ollama real summary — thumbnails/chips, files, difficulty, activities and folder, each with an *Edit* link back to its step. A flat Back/Cancel + Next/Freeze bar sits at the bottom above the safe area (the tab bar hides inside the wizard), and it is portalled to `
` so the - screen entrance animation can never displace it. The desktop page is unchanged. + screen entrance animation can never displace it. While a run is generating, the wizard's + **mode switch hides** — a loading screen can't be swapped to the other wizard mid-flight — + and leaving the page anyway aborts the request instead of saving a deck in the background. + The desktop page is unchanged. - **Native-feel touches (phones)**: the Android Back gesture closes the topmost layer first (sheet, actions sheet, then one wizard step); deleting a deck shows an *Undo* toast instead of a confirm; the deck menu can share a deck as JSON through the system share @@ -1034,9 +1037,12 @@ Things I chose while building, with the reasoning: Drawer-only destinations were re-homed: Progress and Exam became tabs, the New deck screen got a **Study deck ⇄ Make my homework** segmented switch (also on `/homework`), and the library's phone row gained a **⋯** sheet with Import JSON + New folder (folder chips still appear only - once a folder exists). Verified by the mobile suite (134 checks: no hamburger/drawer, tab order, - the label matrix, per-tab routing, deep links, Back from every tab and the ⋯ sheet) plus the - other ten standing suites. + once a folder exists). The mode switch is hidden while either wizard is generating + (`lib/wizard-busy.ts`), and leaving a wizard mid-run aborts the request so a stray generation + can never save a deck or yank the user into the study feed. Verified by the mobile suite + (134 checks: no hamburger/drawer, tab order, the label matrix, per-tab routing, deep links, + Back from every tab and the ⋯ sheet) plus the wizard suite (92 checks, including the + loading-lock and abort-on-leave cases) and the other standing suites. 36. **The mobile declutter pass reshapes, it doesn't fork.** Phones (≤639px) get a 3-step deck flow and a 2-step homework flow that share the exact state and handlers with the desktop diff --git a/components/UploadScreen.tsx b/components/UploadScreen.tsx index 12c1fb3..0efbd57 100644 --- a/components/UploadScreen.tsx +++ b/components/UploadScreen.tsx @@ -42,6 +42,7 @@ import { useBackClose } from "@/lib/use-back-close"; import { useIsPhone } from "@/lib/use-phone"; import { useOnline } from "@/lib/use-online"; import { clearWizardDraft, loadWizardDraft, saveWizardDraft } from "@/lib/wizard-draft"; +import { wizardBusy } from "@/lib/wizard-busy"; import { cn, uid } from "@/lib/utils"; import { CameraIcon, ChevronDownIcon, FolderIcon, IceCubeIcon, PlusIcon, SnowflakeIcon, SparklesIcon, SunIcon } from "@/components/icons"; import { SegmentedPill } from "@/components/SegmentedPill"; @@ -164,6 +165,17 @@ export function UploadScreen() { documentsRef.current = documents; }, [documents]); + /* A loading run locks the mode switch (see WizardModeSwitch). */ + useEffect(() => { + wizardBusy.set(phase === "loading"); + }, [phase]); + useEffect(() => () => wizardBusy.set(false), []); + + /* Leaving the page mid-generation stops the request instead of letting it + finish invisibly and save a deck the user never sees. The loading + screen's Cancel button is the in-page way out. */ + useEffect(() => () => abortRef.current?.abort(), []); + const addFiles = useCallback(async (files: File[]) => { if (files.length === 0) return; setFileError(null); diff --git a/components/WizardModeSwitch.tsx b/components/WizardModeSwitch.tsx index 58094d3..b9362ce 100644 --- a/components/WizardModeSwitch.tsx +++ b/components/WizardModeSwitch.tsx @@ -5,16 +5,21 @@ import Link from "next/link"; import { SegmentedPill } from "@/components/SegmentedPill"; import { useI18n } from "@/lib/i18n"; import { useIsPhone } from "@/lib/use-phone"; +import { useWizardBusy } from "@/lib/wizard-busy"; import { cn } from "@/lib/utils"; /** * In-page switch between the two wizards (New deck ⇄ Make my homework). * Phones reach both through this control and the centre tab; desktop keeps - * the rail rows as well. + * the rail rows as well. Hidden while either wizard is generating: leaving a + * loading run through it would abandon the request mid-flight. */ export function WizardModeSwitch({ mode }: { mode: "deck" | "homework" }) { const { t } = useI18n(); const isPhone = useIsPhone(); + const busy = useWizardBusy(); + + if (busy) return null; return (