Exam Edit on ExamList
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import defaultModuleSettings from "../defaults";
|
||||
import ExamEditorStore from "../types";
|
||||
import { Exam, ExerciseOnlyExam, PartExam } from "@/interfaces/exam";
|
||||
import defaultModuleSettings, { defaultSectionSettings, defaultSettings, sectionLabels } from "../defaults";
|
||||
import ExamEditorStore, { SectionState } from "../types";
|
||||
import { MODULE_ACTIONS, ModuleActions, moduleReducer } from "./moduleReducer";
|
||||
import { SECTION_ACTIONS, SectionActions, sectionReducer } from "./sectionReducer";
|
||||
import { Module } from "@/interfaces";
|
||||
import { updateExamWithUserSolutions } from "@/stores/exam/utils";
|
||||
import { defaultExamUserSolutions } from "@/utils/exams";
|
||||
|
||||
type UpdateRoot = {
|
||||
type: 'UPDATE_ROOT';
|
||||
@@ -9,9 +13,9 @@ type UpdateRoot = {
|
||||
updates: Partial<ExamEditorStore>
|
||||
}
|
||||
};
|
||||
type FullReset = { type: 'FULL_RESET' };
|
||||
type RootActions = { type: 'FULL_RESET' } | { type: "INIT_EXAM_EDIT", payload: { exam: Exam; examModule: Module; id: string } };
|
||||
|
||||
export type Action = ModuleActions | SectionActions | UpdateRoot | FullReset;
|
||||
export type Action = ModuleActions | SectionActions | UpdateRoot | RootActions;
|
||||
|
||||
export const rootReducer = (
|
||||
state: ExamEditorStore,
|
||||
@@ -63,7 +67,64 @@ export const rootReducer = (
|
||||
listening: defaultModuleSettings("listening", 30),
|
||||
level: defaultModuleSettings("level", 60)
|
||||
},
|
||||
};
|
||||
case 'INIT_EXAM_EDIT': {
|
||||
const { exam, id, examModule } = action.payload;
|
||||
let typedExam;
|
||||
let examState;
|
||||
|
||||
|
||||
if (["reading", "listening", "level"].includes(examModule)) {
|
||||
typedExam = updateExamWithUserSolutions(exam, defaultExamUserSolutions(exam)) as PartExam;
|
||||
examState = typedExam.parts.map((part, index) => {
|
||||
return {
|
||||
...defaultSectionSettings(examModule, index + 1, part),
|
||||
sectionId: index + 1,
|
||||
settings: {
|
||||
...defaultSettings(examModule),
|
||||
category: part.category,
|
||||
introOption: { label: 'Custom', value: 'Custom' },
|
||||
currentIntro: part.intro
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
} else {
|
||||
typedExam = updateExamWithUserSolutions(exam, defaultExamUserSolutions(exam)) as ExerciseOnlyExam;
|
||||
examState = typedExam.exercises.map((exercise, index) => {
|
||||
return {
|
||||
...defaultSectionSettings(examModule, index + 1),
|
||||
sectionId: index + 1,
|
||||
settings: {
|
||||
...defaultSettings(examModule),
|
||||
category: exercise.category,
|
||||
introOption: { label: 'Custom', value: 'Custom' },
|
||||
currentIntro: exercise.intro
|
||||
},
|
||||
state: exercise,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
title: id,
|
||||
modules: {
|
||||
...state.modules,
|
||||
[examModule]: {
|
||||
...defaultModuleSettings(examModule, exam.minTimer),
|
||||
examLabel: exam.label,
|
||||
difficulty: exam.difficulty,
|
||||
isPrivate: exam.private,
|
||||
sections: examState,
|
||||
importModule: false,
|
||||
sectionLabels:
|
||||
exam.module === "level" ?
|
||||
sectionLabels(examModule, exam.parts.length) :
|
||||
sectionLabels(examModule)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user