// Extended onboarding — replaces the 3-step flow from home.jsx. // Steps: name → exam type → target band → placement diagnostic → level → prep months → daily minutes → done. // ─── Diagnostic helpers (module scope — pure, no component state) ───────── // Correct-% → rough current band. Linear 0%→4.5, 100%→9.0; a short 14-item // quiz can't resolve finer than this, so results are always snapped to the // nearest 0.5 band. function diagBandFromPct(pct) { const band = 4.5 + pct * 4.5; return Math.max(4, Math.min(9, Math.round(band * 2) / 2)); } function diagLevelFromBand(band) { if (band < 6) return 1; if (band < 7.5) return 2; return 3; } // Builds 6 vocab MCQs (2 per level) from the loaded vocab dataset — reuses // existing word/definition pairs rather than a separate content file. function pickVocabDiagnostic() { const vocab = window.VOCAB || []; const byLevel = { 1: [], 2: [], 3: [] }; for (const w of vocab) if (byLevel[w.lvl] && w.d) byLevel[w.lvl].push(w); const picks = []; [1, 2, 3].forEach(lvl => { const shuffled = [...byLevel[lvl]].sort(() => Math.random() - 0.5); picks.push(...shuffled.slice(0, 2)); }); return picks.map((word, i) => { const distractorPool = vocab.filter(w => w.d && w.w !== word.w && w.d !== word.d); const distractors = [...distractorPool].sort(() => Math.random() - 0.5).slice(0, 3).map(w => w.d); if (distractors.length < 3) return null; const options = [word.d, ...distractors].sort(() => Math.random() - 0.5); return { id: 'v' + i, word: word.w, options, correctIndex: options.indexOf(word.d) }; }).filter(Boolean); } function Onboarding({ initialName, onFinish }) { const [step, setStep] = useState(0); const [name, setName] = useState(initialName || ''); const [examType, setExamType] = useState(null); const [targetBand, setTargetBand] = useState(7); const [level, setLevel] = useState(1); const [prepMonths, setPrepMonths] = useState(3); const [dailyMinutes, setDailyMinutes] = useState(60); // ── Diagnostic (step 3) state ── const [diagPhase, setDiagPhase] = useState('intro'); // intro|vocab|grammar|writing|summary const [vocabQs] = useState(() => pickVocabDiagnostic()); const grammarQs = window.DIAGNOSTIC_GRAMMAR || []; const [qIdx, setQIdx] = useState(0); const [vocabCorrect, setVocabCorrect] = useState(0); const [grammarCorrect, setGrammarCorrect] = useState(0); const [selectedOpt, setSelectedOpt] = useState(null); const [locked, setLocked] = useState(false); const [writingText, setWritingText] = useState(''); const [writingStatus, setWritingStatus] = useState('idle'); // idle|scoring|error const [diagResult, setDiagResult] = useState(null); const startDiagnostic = () => { if (vocabQs.length > 0) setDiagPhase('vocab'); else if (grammarQs.length > 0) setDiagPhase('grammar'); else finishDiagnostic(null); }; const skipDiagnostic = () => { setDiagResult({ skipped: true }); setStep(4); }; const chooseOption = (i, correctIndex, isVocab) => { if (locked) return; setSelectedOpt(i); setLocked(true); if (i === correctIndex) { if (isVocab) setVocabCorrect(c => c + 1); else setGrammarCorrect(c => c + 1); } }; const nextQuestion = (isVocab) => { setSelectedOpt(null); setLocked(false); const list = isVocab ? vocabQs : grammarQs; if (qIdx + 1 < list.length) { setQIdx(i => i + 1); } else if (isVocab) { setQIdx(0); if (grammarQs.length > 0) setDiagPhase('grammar'); else setDiagPhase('writing'); } else { setDiagPhase('writing'); } }; const finishDiagnostic = (writingBand) => { const vocabTotal = vocabQs.length, grammarTotal = grammarQs.length; const correct = vocabCorrect + grammarCorrect; const total = vocabTotal + grammarTotal; const objectivePct = total > 0 ? correct / total : 0.5; const objectiveBand = diagBandFromPct(objectivePct); const estimatedBand = writingBand != null ? Math.round((0.6 * objectiveBand + 0.4 * writingBand) * 2) / 2 : objectiveBand; const estimatedLevel = diagLevelFromBand(estimatedBand); setDiagResult({ skipped: false, vocabCorrect, vocabTotal, grammarCorrect, grammarTotal, writingBand, estimatedBand, estimatedLevel }); setLevel(estimatedLevel); setDiagPhase('summary'); }; const submitWriting = async () => { setWritingStatus('scoring'); try { const p = window.DIAGNOSTIC_WRITING_PROMPT; const res = await window.apiClient.ai.writingScore(p.task, p.exam_type, p.prompt, writingText); finishDiagnostic(typeof res.overall_band === 'number' ? res.overall_band : null); } catch (e) { // Guests aren't authenticated yet and AI providers can be flaky — the // diagnostic must never block onboarding on this being available. setWritingStatus('error'); finishDiagnostic(null); } }; const finalize = () => { const startDate = new Date().toISOString().slice(0, 10); const profile = { examType, prepMonths, dailyMinutes, startDate, examDate: null, diagnostic: diagResult, }; const plan = window.planEngine.generate({ examType, targetBand, level, prepMonths, dailyMinutes, startDate, }); onFinish({ userName: (name || 'Learner').trim(), targetBand, level, profile, plan, onboarded: true, }); }; const totalSteps = 7; const stepLabel = `Step ${step + 1} of ${totalSteps}`; return (
Just a name for the dashboard.
setName(e.target.value)} placeholder="e.g. Arif" maxLength={40} />Different content, different writing tasks. Pick the one you'll register for.
Pick the score you need. We'll adjust everything around this — vocabulary, quizzes, grammar, and mock test difficulty.
Be honest — we'll keep adjusting as you progress.
{diagResult && !diagResult.skipped && (We'll lay out a week-by-week plan that paces vocabulary, grammar, and mock tests.
We'll size the daily plan to fit. You can change this later in Settings.
2 minutes: a few vocabulary and grammar questions, plus an optional short writing sample. We use this to set your starting level instead of just guessing — you can still adjust it afterward.
A couple of sentences is enough — this only refines the estimate.