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:
@@ -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 = {};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user