Added listening import, part divider was showing between questions because it was with exerciseIndex instead of partIndex, fixed a reorder bug when deleting questions
This commit is contained in:
@@ -6,7 +6,7 @@ import { capitalize } from 'lodash';
|
|||||||
import { Module } from '@/interfaces';
|
import { Module } from '@/interfaces';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
import useExamEditorStore from '@/stores/examEditor';
|
import useExamEditorStore from '@/stores/examEditor';
|
||||||
import { LevelPart, ReadingPart } from '@/interfaces/exam';
|
import { LevelPart, ListeningPart, ReadingPart } from '@/interfaces/exam';
|
||||||
import { defaultSectionSettings } from '@/stores/examEditor/defaults';
|
import { defaultSectionSettings } from '@/stores/examEditor/defaults';
|
||||||
|
|
||||||
const WordUploader: React.FC<{ module: Module }> = ({ module }) => {
|
const WordUploader: React.FC<{ module: Module }> = ({ module }) => {
|
||||||
@@ -71,46 +71,20 @@ const WordUploader: React.FC<{ module: Module }> = ({ module }) => {
|
|||||||
setSolutionsFile(null);
|
setSolutionsFile(null);
|
||||||
setShowUploaders(false);
|
setShowUploaders(false);
|
||||||
|
|
||||||
switch (currentModule) {
|
const newSectionsStates = data.parts.map(
|
||||||
case 'reading': {
|
(part: ReadingPart | ListeningPart | LevelPart, index: number) => defaultSectionSettings(module, index + 1, part)
|
||||||
const newSectionsStates = data.parts.map(
|
);
|
||||||
(part: ReadingPart, index: number) => defaultSectionSettings(module, index + 1, part)
|
dispatch({
|
||||||
);
|
type: "UPDATE_MODULE", payload: {
|
||||||
dispatch({
|
updates: {
|
||||||
type: "UPDATE_MODULE", payload: {
|
sections: newSectionsStates,
|
||||||
updates: {
|
minTimer: data.minTimer,
|
||||||
sections: newSectionsStates,
|
importModule: false,
|
||||||
minTimer: data.minTimer,
|
importing: false,
|
||||||
importModule: false,
|
},
|
||||||
importing: false,
|
module
|
||||||
},
|
|
||||||
module
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
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) {
|
} catch (error) {
|
||||||
toast.error(`Make sure you've imported a valid word document (.docx)!`);
|
toast.error(`Make sure you've imported a valid word document (.docx)!`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export default function Level({ exam, showSolutions = false, onFinish, preview =
|
|||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
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);
|
setShowPartDivider(true);
|
||||||
setBgColor(levelBgColor);
|
setBgColor(levelBgColor);
|
||||||
}
|
}
|
||||||
@@ -173,8 +173,6 @@ export default function Level({ exam, showSolutions = false, onFinish, preview =
|
|||||||
setBgColor(levelBgColor);
|
setBgColor(levelBgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
setSeenParts(prev => new Set(prev).add(partIndex + 1));
|
|
||||||
|
|
||||||
if (partIndex < exam.parts.length - 1 && exam.parts[partIndex + 1].context && !textRenderDisabled) {
|
if (partIndex < exam.parts.length - 1 && exam.parts[partIndex + 1].context && !textRenderDisabled) {
|
||||||
setTextRender(true);
|
setTextRender(true);
|
||||||
}
|
}
|
||||||
@@ -223,7 +221,6 @@ export default function Level({ exam, showSolutions = false, onFinish, preview =
|
|||||||
setBgColor(levelBgColor);
|
setBgColor(levelBgColor);
|
||||||
setShowPartDivider(true);
|
setShowPartDivider(true);
|
||||||
setQuestionIndex(0);
|
setQuestionIndex(0);
|
||||||
setSeenParts(prev => new Set(prev).add(partIndex - 1));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,7 +517,7 @@ export default function Level({ exam, showSolutions = false, onFinish, preview =
|
|||||||
defaultTitle="Placement Test"
|
defaultTitle="Placement Test"
|
||||||
section={exam.parts[partIndex]}
|
section={exam.parts[partIndex]}
|
||||||
sectionIndex={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 && (
|
{exam.parts[0].intro && (
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import { ModuleState } from "../types";
|
|||||||
import ReorderResult from "./types";
|
import ReorderResult from "./types";
|
||||||
|
|
||||||
const reorderFillBlanks = (exercise: FillBlanksExercise, startId: number): ReorderResult<FillBlanksExercise> => {
|
const reorderFillBlanks = (exercise: FillBlanksExercise, startId: number): ReorderResult<FillBlanksExercise> => {
|
||||||
let idMapping = exercise.solutions
|
let idMapping = [...exercise.solutions]
|
||||||
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
||||||
.reduce((acc, solution, index) => {
|
.reduce((acc, solution, index) => {
|
||||||
acc[solution.id] = (startId + index).toString();
|
acc[solution.id] = (startId + index).toString();
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
}, {} as Record<string, string>);
|
||||||
|
|
||||||
let newSolutions = exercise.solutions
|
let newSolutions = [...exercise.solutions]
|
||||||
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
||||||
.map((solution, index) => ({
|
.map((solution, index) => ({
|
||||||
...solution,
|
...solution,
|
||||||
@@ -84,7 +84,7 @@ const reorderWriteBlanks = (exercise: WriteBlanksExercise, startId: number): Reo
|
|||||||
};
|
};
|
||||||
|
|
||||||
const reorderTrueFalse = (exercise: TrueFalseExercise, startId: number): ReorderResult<TrueFalseExercise> => {
|
const reorderTrueFalse = (exercise: TrueFalseExercise, startId: number): ReorderResult<TrueFalseExercise> => {
|
||||||
let newQuestions = exercise.questions
|
let newQuestions = [...exercise.questions]
|
||||||
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
||||||
.map((question, index) => ({
|
.map((question, index) => ({
|
||||||
...question,
|
...question,
|
||||||
@@ -101,7 +101,7 @@ const reorderTrueFalse = (exercise: TrueFalseExercise, startId: number): Reorder
|
|||||||
};
|
};
|
||||||
|
|
||||||
const reorderMatchSentences = (exercise: MatchSentencesExercise, startId: number): ReorderResult<MatchSentencesExercise> => {
|
const reorderMatchSentences = (exercise: MatchSentencesExercise, startId: number): ReorderResult<MatchSentencesExercise> => {
|
||||||
let newSentences = exercise.sentences
|
let newSentences = [...exercise.sentences]
|
||||||
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
||||||
.map((sentence, index) => ({
|
.map((sentence, index) => ({
|
||||||
...sentence,
|
...sentence,
|
||||||
@@ -119,7 +119,7 @@ const reorderMatchSentences = (exercise: MatchSentencesExercise, startId: number
|
|||||||
|
|
||||||
|
|
||||||
const reorderMultipleChoice = (exercise: MultipleChoiceExercise, startId: number): ReorderResult<MultipleChoiceExercise> => {
|
const reorderMultipleChoice = (exercise: MultipleChoiceExercise, startId: number): ReorderResult<MultipleChoiceExercise> => {
|
||||||
let newQuestions = exercise.questions
|
let newQuestions = [...exercise.questions]
|
||||||
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
.sort((a, b) => parseInt(a.id) - parseInt(b.id))
|
||||||
.map((question, index) => ({
|
.map((question, index) => ({
|
||||||
...question,
|
...question,
|
||||||
|
|||||||
Reference in New Issue
Block a user