Files
encoach_frontend/src/stores/examEditor/defaults.ts

120 lines
3.5 KiB
TypeScript

import { Module } from "@/interfaces"
import { Difficulty} from "@/interfaces/exam"
import { sample } from "lodash"
import { ExamPart, ModuleState, SectionState } from "./types"
import { levelPart, listeningSection, readingPart, speakingTask, writingTask } from "@/stores/examEditor/sections"
const defaultSettings = (module: Module) => {
const baseSettings = {
category: '',
introOption: { label: 'None', value: 'None' },
customIntro: '',
currentIntro: '',
topic: '',
isCategoryDropdownOpen: false,
isIntroDropdownOpen: false,
isExerciseDropdownOpen: false,
}
switch (module) {
case 'reading':
return {
...baseSettings,
isPassageOpen: false,
}
case 'listening':
return {
...baseSettings,
isAudioContextOpen: false
}
default:
return baseSettings;
}
}
const sectionLabels = (module: Module) => {
switch (module) {
case 'reading':
return Array.from({ length: 3 }, (_, index) => ({
id: index + 1,
label: `Passage ${index + 1}`
}));
case 'writing':
return [{id: 1, label: "Task 1"}, {id: 2, label: "Task 2"}];
case 'speaking':
return [{id: 1, label: "Speaking 1"}, {id: 2, label: "Speaking 2"}, {id: 3, label: "Interactive Speaking"}];
case 'listening':
return Array.from({ length: 4 }, (_, index) => ({
id: index + 1,
label: `Section ${index + 1}`
}));
case 'level':
return [{id: 1, label: "Part 1"}];
}
}
const defaultExamLabel = (module: Module) => {
switch (module) {
case 'reading':
return "Reading Exam";
case 'writing':
return "Writing Exam";
case 'speaking':
return "Speaking Exam";
case 'listening':
return "Listening Exam";
case 'level':
return "Placement Test";
}
}
const defaultSection = (module: Module, sectionId: number) => {
switch (module) {
case 'reading':
return readingPart(sectionId);
case 'writing':
return writingTask(sectionId);
case 'listening':
return listeningSection(sectionId)
case 'speaking':
return speakingTask(sectionId)
case 'level':
return levelPart(sectionId)
}
}
export const defaultSectionSettings = (module: Module, sectionId: number, part?: ExamPart) => {
return {
sectionId: sectionId,
sectionLabel: "",
settings: defaultSettings(module),
state: part !== undefined ? part : defaultSection(module, sectionId),
generating: undefined,
genResult: undefined,
expandedSubSections: [],
exercisePickerState: [],
selectedExercises: [],
}
}
const defaultModuleSettings = (module: Module, minTimer: number, states?: SectionState[]): ModuleState => {
const state: ModuleState = {
examLabel: defaultExamLabel(module),
minTimer,
difficulty: sample(["easy", "medium", "hard"] as Difficulty[])!,
isPrivate: false,
sectionLabels: sectionLabels(module),
expandedSections: [1],
focusedSection: 1,
sections: [defaultSectionSettings(module, 1)],
importModule: true,
importing: false,
edit: [],
};
return state;
}
export default defaultModuleSettings;