From 8c14bfad456ac15c81a9022a2f2aede27391015b Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Mon, 29 Jun 2026 07:18:58 +0100 Subject: [PATCH] fix(exercise): show correct submitted state and real questions for students MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- apps/dashboard/src/lib/features/course/api/lesson.svelte.ts | 4 ++++ .../lib/features/course/components/exercise/view-mode.svelte | 3 ++- apps/dashboard/src/lib/features/course/pages/exercise.svelte | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/src/lib/features/course/api/lesson.svelte.ts b/apps/dashboard/src/lib/features/course/api/lesson.svelte.ts index 2a362be9..81178fa2 100644 --- a/apps/dashboard/src/lib/features/course/api/lesson.svelte.ts +++ b/apps/dashboard/src/lib/features/course/api/lesson.svelte.ts @@ -204,6 +204,10 @@ export class LessonApi extends BaseApiWithErrors { logContext: 'deleting lesson', onSuccess: (response) => { if (response.data) { + this.sections = this.sections.map((section) => ({ + ...section, + lessons: section.lessons.filter((l) => l.id !== lessonId) + })); snackbar.success('snackbar.lessons.lesson_deleted'); this.success = true; this.errors = {}; diff --git a/apps/dashboard/src/lib/features/course/components/exercise/view-mode.svelte b/apps/dashboard/src/lib/features/course/components/exercise/view-mode.svelte index cfe4762b..ef09b0e4 100644 --- a/apps/dashboard/src/lib/features/course/components/exercise/view-mode.svelte +++ b/apps/dashboard/src/lib/features/course/components/exercise/view-mode.svelte @@ -649,6 +649,7 @@ $effect(() => { if (!exerciseId || isFetchingExercise || skipHydrateFromSubmissions) return; + if (!isExerciseLoaded) return; if (!submissionList.length || $questionnaireMetaData.isFinished) return; let idx = selectedTryIndex; if (idx < 0 || idx >= submissionList.length) { @@ -700,7 +701,7 @@ ...m, answers, totalPossibleGrade, - currentQuestionIndex: $questionnaire.questions.length, + currentQuestionIndex: $questionnaire.questions.length + 1, currentSectionIndex: activeSections.length > 0 ? activeSections.length - 1 : 0, sectionPhase: 'questions', isFinished: true, diff --git a/apps/dashboard/src/lib/features/course/pages/exercise.svelte b/apps/dashboard/src/lib/features/course/pages/exercise.svelte index d78bcec6..ffa93264 100644 --- a/apps/dashboard/src/lib/features/course/pages/exercise.svelte +++ b/apps/dashboard/src/lib/features/course/pages/exercise.svelte @@ -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) {