fix(exercise): show correct submitted state and real questions for students

exercise.svelte was auto-adding a QUESTION_TEMPLATE to the store whenever
questions were empty, which raced with hydrateExercisePageData.
applyMySubmission fired with the blank template in place, set
isFinished=true, and the guard prevented re-application once real
questions loaded.

Two fixes: guard the auto-add effect with isOrgStudent (students never
need to add questions), and gate applyMySubmission on isExerciseLoaded
so it always waits for hydrateExercisePageData to populate real questions
first.

Also fix off-by-1 in applyMySubmission (questions.length → questions.length + 1)
so currentQuestion is undefined at end-of-exercise, satisfying the
isFinished derived. Clear questionnaire.questions in onDestroy to prevent
stale questions flashing on the next exercise.

Fix lesson delete not updating sidebar/content list by filtering the
removed lesson from sections on success.
This commit is contained in:
Rotimi Best
2026-06-29 07:18:58 +01:00
parent 513ab5e81f
commit 8c14bfad45
3 changed files with 9 additions and 1 deletions
@@ -269,6 +269,7 @@
onDestroy(() => {
reset();
questionnaire.update((q) => ({ ...q, questions: [] }));
});
onMount(() => {
@@ -309,6 +310,8 @@
});
$effect(() => {
if ($isOrgStudent) return;
const addNewQ = $questionnaire?.questions?.length < 1;
if (addNewQ) {