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',
|
logContext: 'deleting lesson',
|
||||||
onSuccess: (response) => {
|
onSuccess: (response) => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
|
this.sections = this.sections.map((section) => ({
|
||||||
|
...section,
|
||||||
|
lessons: section.lessons.filter((l) => l.id !== lessonId)
|
||||||
|
}));
|
||||||
snackbar.success('snackbar.lessons.lesson_deleted');
|
snackbar.success('snackbar.lessons.lesson_deleted');
|
||||||
this.success = true;
|
this.success = true;
|
||||||
this.errors = {};
|
this.errors = {};
|
||||||
|
|||||||
@@ -649,6 +649,7 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!exerciseId || isFetchingExercise || skipHydrateFromSubmissions) return;
|
if (!exerciseId || isFetchingExercise || skipHydrateFromSubmissions) return;
|
||||||
|
if (!isExerciseLoaded) return;
|
||||||
if (!submissionList.length || $questionnaireMetaData.isFinished) return;
|
if (!submissionList.length || $questionnaireMetaData.isFinished) return;
|
||||||
let idx = selectedTryIndex;
|
let idx = selectedTryIndex;
|
||||||
if (idx < 0 || idx >= submissionList.length) {
|
if (idx < 0 || idx >= submissionList.length) {
|
||||||
@@ -700,7 +701,7 @@
|
|||||||
...m,
|
...m,
|
||||||
answers,
|
answers,
|
||||||
totalPossibleGrade,
|
totalPossibleGrade,
|
||||||
currentQuestionIndex: $questionnaire.questions.length,
|
currentQuestionIndex: $questionnaire.questions.length + 1,
|
||||||
currentSectionIndex: activeSections.length > 0 ? activeSections.length - 1 : 0,
|
currentSectionIndex: activeSections.length > 0 ? activeSections.length - 1 : 0,
|
||||||
sectionPhase: 'questions',
|
sectionPhase: 'questions',
|
||||||
isFinished: true,
|
isFinished: true,
|
||||||
|
|||||||
@@ -269,6 +269,7 @@
|
|||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
reset();
|
reset();
|
||||||
|
questionnaire.update((q) => ({ ...q, questions: [] }));
|
||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -309,6 +310,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
|
if ($isOrgStudent) return;
|
||||||
|
|
||||||
const addNewQ = $questionnaire?.questions?.length < 1;
|
const addNewQ = $questionnaire?.questions?.length < 1;
|
||||||
|
|
||||||
if (addNewQ) {
|
if (addNewQ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user