diff --git a/src/components/ExamEditor/ImportExam/WordUploader.tsx b/src/components/ExamEditor/ImportExam/WordUploader.tsx index c52a4620..2a314599 100644 --- a/src/components/ExamEditor/ImportExam/WordUploader.tsx +++ b/src/components/ExamEditor/ImportExam/WordUploader.tsx @@ -6,7 +6,7 @@ import { capitalize } from 'lodash'; import { Module } from '@/interfaces'; import { toast } from 'react-toastify'; import useExamEditorStore from '@/stores/examEditor'; -import { LevelPart, ReadingPart } from '@/interfaces/exam'; +import { LevelPart, ListeningPart, ReadingPart } from '@/interfaces/exam'; import { defaultSectionSettings } from '@/stores/examEditor/defaults'; const WordUploader: React.FC<{ module: Module }> = ({ module }) => { @@ -71,46 +71,20 @@ const WordUploader: React.FC<{ module: Module }> = ({ module }) => { setSolutionsFile(null); setShowUploaders(false); - switch (currentModule) { - case 'reading': { - const newSectionsStates = data.parts.map( - (part: ReadingPart, index: number) => defaultSectionSettings(module, index + 1, part) - ); - dispatch({ - type: "UPDATE_MODULE", payload: { - updates: { - sections: newSectionsStates, - minTimer: data.minTimer, - importModule: false, - importing: false, - }, - module - } - }); - break; + const newSectionsStates = data.parts.map( + (part: ReadingPart | ListeningPart | LevelPart, index: number) => defaultSectionSettings(module, index + 1, part) + ); + dispatch({ + type: "UPDATE_MODULE", payload: { + updates: { + sections: newSectionsStates, + minTimer: data.minTimer, + importModule: false, + importing: false, + }, + module } - case 'level': { - const newSectionsStates = data.parts.map( - (part: LevelPart, index: number) => defaultSectionSettings(module, index + 1, part) - ); - dispatch({ - type: "UPDATE_MODULE", payload: { - updates: { - sections: newSectionsStates, - minTimer: data.minTimer, - importModule: false, - importing: false, - sectionLabels: Array.from({ length: newSectionsStates.length }, (_, index) => ({ - id: index + 1, - label: `Part ${index + 1}` - })) - }, - module - } - }); - break; - } - } + }); } catch (error) { toast.error(`Make sure you've imported a valid word document (.docx)!`); } finally { diff --git a/src/exams/Level/index.tsx b/src/exams/Level/index.tsx index baef3ca1..64a54f86 100644 --- a/src/exams/Level/index.tsx +++ b/src/exams/Level/index.tsx @@ -79,7 +79,7 @@ export default function Level({ exam, showSolutions = false, onFinish, preview = useEffect(() => { - if (!showSolutions && exam.parts[partIndex]?.intro !== undefined && exam.parts[partIndex]?.intro !== "" && !seenParts.has(exerciseIndex)) { + if (!showSolutions && exam.parts[partIndex]?.intro !== undefined && exam.parts[partIndex]?.intro !== "" && !seenParts.has(partIndex)) { setShowPartDivider(true); setBgColor(levelBgColor); } @@ -173,8 +173,6 @@ export default function Level({ exam, showSolutions = false, onFinish, preview = setBgColor(levelBgColor); } - setSeenParts(prev => new Set(prev).add(partIndex + 1)); - if (partIndex < exam.parts.length - 1 && exam.parts[partIndex + 1].context && !textRenderDisabled) { setTextRender(true); } @@ -223,7 +221,6 @@ export default function Level({ exam, showSolutions = false, onFinish, preview = setBgColor(levelBgColor); setShowPartDivider(true); setQuestionIndex(0); - setSeenParts(prev => new Set(prev).add(partIndex - 1)); return; } @@ -520,7 +517,7 @@ export default function Level({ exam, showSolutions = false, onFinish, preview = defaultTitle="Placement Test" section={exam.parts[partIndex]} sectionIndex={partIndex} - onNext={() => { setShowPartDivider(false); setStartNow(false); setBgColor("bg-white"); }} + onNext={() => { setShowPartDivider(false); setStartNow(false); setBgColor("bg-white"); setSeenParts(prev => new Set(prev).add(partIndex)); }} /> : ( <> {exam.parts[0].intro && ( diff --git a/src/stores/examEditor/reorder/global.ts b/src/stores/examEditor/reorder/global.ts index a1b1535d..f2918bf0 100644 --- a/src/stores/examEditor/reorder/global.ts +++ b/src/stores/examEditor/reorder/global.ts @@ -3,14 +3,14 @@ import { ModuleState } from "../types"; import ReorderResult from "./types"; const reorderFillBlanks = (exercise: FillBlanksExercise, startId: number): ReorderResult => { - let idMapping = exercise.solutions + let idMapping = [...exercise.solutions] .sort((a, b) => parseInt(a.id) - parseInt(b.id)) .reduce((acc, solution, index) => { acc[solution.id] = (startId + index).toString(); return acc; }, {} as Record); - let newSolutions = exercise.solutions + let newSolutions = [...exercise.solutions] .sort((a, b) => parseInt(a.id) - parseInt(b.id)) .map((solution, index) => ({ ...solution, @@ -84,7 +84,7 @@ const reorderWriteBlanks = (exercise: WriteBlanksExercise, startId: number): Reo }; const reorderTrueFalse = (exercise: TrueFalseExercise, startId: number): ReorderResult => { - let newQuestions = exercise.questions + let newQuestions = [...exercise.questions] .sort((a, b) => parseInt(a.id) - parseInt(b.id)) .map((question, index) => ({ ...question, @@ -101,7 +101,7 @@ const reorderTrueFalse = (exercise: TrueFalseExercise, startId: number): Reorder }; const reorderMatchSentences = (exercise: MatchSentencesExercise, startId: number): ReorderResult => { - let newSentences = exercise.sentences + let newSentences = [...exercise.sentences] .sort((a, b) => parseInt(a.id) - parseInt(b.id)) .map((sentence, index) => ({ ...sentence, @@ -119,7 +119,7 @@ const reorderMatchSentences = (exercise: MatchSentencesExercise, startId: number const reorderMultipleChoice = (exercise: MultipleChoiceExercise, startId: number): ReorderResult => { - let newQuestions = exercise.questions + let newQuestions = [...exercise.questions] .sort((a, b) => parseInt(a.id) - parseInt(b.id)) .map((question, index) => ({ ...question,