Skip to content

Commit 54ffe63

Browse files
author
psriraj3
committed
Tightning up Focus Mode during exam.
1 parent 3ad19ca commit 54ffe63

6 files changed

Lines changed: 317 additions & 302 deletions

File tree

dist/assets/index-BfQhuYO5.js

Lines changed: 291 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets/index-CNIGOKbX.js

Lines changed: 0 additions & 287 deletions
This file was deleted.

dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
1010
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1111
<title>FUNton</title>
12-
<script type="module" crossorigin src="/assets/index-CNIGOKbX.js"></script>
12+
<script type="module" crossorigin src="/assets/index-BfQhuYO5.js"></script>
1313
<link rel="stylesheet" crossorigin href="/assets/index-DmekIFy3.css">
1414
</head>
1515
<body>

src/App.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default function App() {
9999
const [view, setView] = useState<View>("main");
100100

101101
const [mode, setMode] = useState<Mode>("practice");
102+
const [focusRunning, setFocusRunning] = useState(false);
102103
const [subject, setSubject] = useState<Subject>("maths");
103104
const [ukYear, setUkYear] = useState(4);
104105
const [difficulty, setDifficulty] = useState(6);
@@ -211,20 +212,24 @@ export default function App() {
211212
<button
212213
type="button"
213214
className="brand"
215+
disabled={focusRunning}
214216
onClick={() => {
217+
if (focusRunning) return;
215218
setView("main");
216219
setMode("practice");
217220
}}
218221
aria-label="Go to Practice Mode"
219-
title="Go to Practice Mode"
222+
title={focusRunning ? "Finish the exam to switch modes" : "Go to Practice Mode"}
220223
>
221224
<img className="brandLogo" src="/logo.png" alt="FUNton" />
222225
</button>
223226

224227
<div className="appHeaderRight">
225228
<ModeSwitch
226229
mode={mode}
230+
disabledModes={focusRunning ? { practice: true, worksheet: true } : undefined}
227231
onChange={(m) => {
232+
if (focusRunning && m !== "focus") return;
228233
setMode(m);
229234
// If user changes mode while on review/thanks, bring them back
230235
if (view !== "main") setView("main");
@@ -326,7 +331,8 @@ export default function App() {
326331
ukYear={ukYear}
327332
difficulty={difficulty}
328333
seed={seed}
329-
topic={topic} // ✅ whatever your maths topic state variable is
334+
topic={topic}
335+
onRunningChange={setFocusRunning}
330336
/>
331337
) : mode === "practice" ? (
332338
<PracticeRunner key={generated.seed} set={generated} />

src/ui/FocusMode.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Props = {
1010
difficulty: number;
1111
seed?: string;
1212
topic?: MathsTopic; // ✅ add
13+
onRunningChange?: (running: boolean) => void;
1314
};
1415

1516
type Phase = "setup" | "running" | "done";
@@ -520,7 +521,7 @@ function tierCopy(ukYear: number, tier: "fail" | "pass" | "fantastic", name: str
520521
};
521522
}
522523

523-
export function FocusMode({ subject, ukYear, difficulty, seed, topic }: Props) {
524+
export function FocusMode({ subject, ukYear, difficulty, seed, topic, onRunningChange }: Props) {
524525
const [phase, setPhase] = useState<Phase>("setup");
525526
const [showReview, setShowReview] = useState(false);
526527
const [onlyWrong, setOnlyWrong] = useState(false);
@@ -546,6 +547,13 @@ export function FocusMode({ subject, ukYear, difficulty, seed, topic }: Props) {
546547
if (phase !== "running") setNavOpen(false);
547548
}, [phase]);
548549

550+
551+
// Notify parent (App) when exam starts/ends so it can lock mode switching
552+
useEffect(() => {
553+
onRunningChange?.(phase === "running");
554+
return () => onRunningChange?.(false);
555+
}, [phase, onRunningChange]);
556+
549557
// ===== Refs to avoid stale state in timer/lockdown auto-submit =====
550558
const phaseRef = useRef<Phase>(phase);
551559
const configRef = useRef<FocusConfig>(config);

src/ui/ModeSwitch.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
// type Mode = "practice" | "worksheet";
22
export type Mode = "practice" | "worksheet" | "focus";
3-
export function ModeSwitch(props: { mode: Mode; onChange: (m: Mode) => void }) {
4-
const { mode, onChange } = props;
3+
export function ModeSwitch(props: { mode: Mode; onChange: (m: Mode) => void; disabledModes?: Partial<Record<Mode, boolean>> }) {
4+
const { mode, onChange, disabledModes } = props;
55

6-
const btnStyle = (active: boolean): React.CSSProperties => ({
6+
const btnStyle = (active: boolean, disabled: boolean): React.CSSProperties => ({
77
padding: "10px 12px",
88
borderRadius: 10,
99
border: "1px solid #ddd",
1010
background: active ? "#111" : "#fff",
1111
color: active ? "#fff" : "#111",
12-
cursor: "pointer"
12+
cursor: disabled ? "not-allowed" : "pointer",
13+
opacity: disabled ? 0.55 : 1
1314
});
1415

1516
return (
1617
<div style={{ display: "flex", gap: 8 }}>
17-
<button style={btnStyle(mode === "practice")} onClick={() => onChange("practice")}>
18+
<button disabled={!!disabledModes?.practice} style={btnStyle(mode === "practice", !!disabledModes?.practice)} onClick={() => onChange("practice")}>
1819
Practice Mode
1920
</button>
20-
<button style={btnStyle(mode === "worksheet")} onClick={() => onChange("worksheet")}>
21+
<button disabled={!!disabledModes?.worksheet} style={btnStyle(mode === "worksheet", !!disabledModes?.worksheet)} onClick={() => onChange("worksheet")}>
2122
Worksheet PDF
2223
</button>
23-
<button
24-
style={btnStyle(mode === "focus")}
25-
className={mode === "focus" ? "active" : ""}
26-
onClick={() => onChange("focus")}
27-
>
24+
<button disabled={!!disabledModes?.focus} style={btnStyle(mode === "focus", !!disabledModes?.focus)} onClick={() => onChange("focus")}>
2825
Focus (Exam)
2926
</button>
3027
</div>

0 commit comments

Comments
 (0)