Previous commit solved completion but messed up question modal, patched that and added the condition to show the submission modal when all questions are awnswered
This commit is contained in:
@@ -131,6 +131,7 @@ const FillBlanks: React.FC<FillBlanksExercise & CommonProps> = ({
|
|||||||
<br />
|
<br />
|
||||||
</p>
|
</p>
|
||||||
));
|
));
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [text, variant, renderLines, currentMCSelection]);
|
}, [text, variant, renderLines, currentMCSelection]);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti
|
|||||||
shuffles,
|
shuffles,
|
||||||
hasExamEnded,
|
hasExamEnded,
|
||||||
partIndex,
|
partIndex,
|
||||||
userSolutions: storeUserSolutions,
|
|
||||||
setQuestionIndex,
|
setQuestionIndex,
|
||||||
setUserSolutions,
|
|
||||||
setCurrentSolution
|
setCurrentSolution
|
||||||
} = useExamStore((state) => state);
|
} = useExamStore((state) => state);
|
||||||
|
|
||||||
@@ -91,14 +89,6 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti
|
|||||||
|
|
||||||
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));
|
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setUserSolutions(
|
|
||||||
[...storeUserSolutions.filter((x) => x.exercise !== id), {
|
|
||||||
exercise: id, solutions: answers, score: calculateScore(), type
|
|
||||||
}]);
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [answers]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasExamEnded) onNext({ exercise: id, solutions: answers, score: calculateScore(), type });
|
if (hasExamEnded) onNext({ exercise: id, solutions: answers, score: calculateScore(), type });
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@@ -112,7 +102,7 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrentSolution({ exercise: id, solutions: answers, score: calculateScore(), type, shuffleMaps: shuffleMaps });
|
setCurrentSolution({ exercise: id, solutions: answers, score: calculateScore(), type, shuffleMaps: shuffleMaps });
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [answers])
|
}, [answers, setAnswers])
|
||||||
|
|
||||||
const getShuffledSolution = (originalSolution: string, questionShuffleMap: ShuffleMap) => {
|
const getShuffledSolution = (originalSolution: string, questionShuffleMap: ShuffleMap) => {
|
||||||
for (const [newPosition, originalPosition] of Object.entries(questionShuffleMap.map)) {
|
for (const [newPosition, originalPosition] of Object.entries(questionShuffleMap.map)) {
|
||||||
|
|||||||
@@ -51,12 +51,13 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
|
|||||||
setCurrentSolution
|
setCurrentSolution
|
||||||
} = useExamStore((state) => state);
|
} = useExamStore((state) => state);
|
||||||
|
|
||||||
|
|
||||||
const [multipleChoicesDone, setMultipleChoicesDone] = useState<{ id: string; amount: number }[]>([]);
|
const [multipleChoicesDone, setMultipleChoicesDone] = useState<{ id: string; amount: number }[]>([]);
|
||||||
const [showQuestionsModal, setShowQuestionsModal] = useState(false);
|
const [showQuestionsModal, setShowQuestionsModal] = useState(false);
|
||||||
const [continueAnyways, setContinueAnyways] = useState(false);
|
const [continueAnyways, setContinueAnyways] = useState(false);
|
||||||
const [textRender, setTextRender] = useState(false);
|
const [textRender, setTextRender] = useState(false);
|
||||||
const [changedPrompt, setChangedPrompt] = useState(false);
|
const [changedPrompt, setChangedPrompt] = useState(false);
|
||||||
|
const [nextExerciseCalled, setNextExerciseCalled] = useState(false);
|
||||||
|
const [currentSolutionSet, setCurrentSolutionSet] = useState(false);
|
||||||
|
|
||||||
const [seenParts, setSeenParts] = useState<number[]>(showSolutions ? exam.parts.map((_, index) => index) : [0]);
|
const [seenParts, setSeenParts] = useState<number[]>(showSolutions ? exam.parts.map((_, index) => index) : [0]);
|
||||||
|
|
||||||
@@ -80,6 +81,7 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof currentSolution !== "undefined") {
|
if (typeof currentSolution !== "undefined") {
|
||||||
setUserSolutions([...userSolutions.filter((x) => x.exercise !== currentSolution.exercise), { ...currentSolution, module: "level" as Module, exam: exam.id, shuffleMaps: exam.shuffle ? [...shuffles.find((x) => x.exerciseID == currentExercise?.id)?.shuffles!] : [] }]);
|
setUserSolutions([...userSolutions.filter((x) => x.exercise !== currentSolution.exercise), { ...currentSolution, module: "level" as Module, exam: exam.id, shuffleMaps: exam.shuffle ? [...shuffles.find((x) => x.exerciseID == currentExercise?.id)?.shuffles!] : [] }]);
|
||||||
|
setCurrentSolutionSet(true);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [currentSolution, exam.id, exam.shuffle, shuffles, currentExercise])
|
}, [currentSolution, exam.id, exam.shuffle, shuffles, currentExercise])
|
||||||
@@ -118,8 +120,11 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [partIndex, exerciseIndex, questionIndex]);
|
}, [partIndex, exerciseIndex, questionIndex]);
|
||||||
|
|
||||||
|
const next = () => {
|
||||||
|
setNextExerciseCalled(true);
|
||||||
|
}
|
||||||
|
|
||||||
const nextExercise = (solution?: UserSolution) => {
|
const nextExercise = () => {
|
||||||
scrollToTop();
|
scrollToTop();
|
||||||
|
|
||||||
if (exerciseIndex + 1 < exam.parts[partIndex].exercises.length && !hasExamEnded) {
|
if (exerciseIndex + 1 < exam.parts[partIndex].exercises.length && !hasExamEnded) {
|
||||||
@@ -155,13 +160,27 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(partIndex + 1 === exam.parts.length && exerciseIndex === exam.parts[partIndex].exercises.length - 1 && !continueAnyways) {
|
||||||
|
modalKwargs();
|
||||||
|
setShowQuestionsModal(true);
|
||||||
|
}
|
||||||
|
|
||||||
setHasExamEnded(false);
|
setHasExamEnded(false);
|
||||||
if (typeof showSolutionsSave !== "undefined") {
|
if (typeof showSolutionsSave !== "undefined") {
|
||||||
onFinish(showSolutionsSave);
|
onFinish(showSolutionsSave);
|
||||||
} else {
|
} else {
|
||||||
onFinish(userSolutions);
|
onFinish(userSolutions);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (nextExerciseCalled && currentSolutionSet) {
|
||||||
|
nextExercise();
|
||||||
|
setNextExerciseCalled(false);
|
||||||
|
setCurrentSolutionSet(false);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [nextExerciseCalled, currentSolutionSet])
|
||||||
|
|
||||||
const previousExercise = (solution?: UserSolution) => {
|
const previousExercise = (solution?: UserSolution) => {
|
||||||
scrollToTop();
|
scrollToTop();
|
||||||
@@ -384,13 +403,13 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
|
|||||||
<>
|
<>
|
||||||
{exam.parts[partIndex].context && renderText()}
|
{exam.parts[partIndex].context && renderText()}
|
||||||
{(showSolutions || editing) ?
|
{(showSolutions || editing) ?
|
||||||
renderSolution(currentExercise, nextExercise, previousExercise)
|
renderSolution(currentExercise, nextExercise, previousExercise) :
|
||||||
:
|
renderExercise(currentExercise, exam.id, next, previousExercise)
|
||||||
renderExercise(currentExercise, exam.id, nextExercise, previousExercise)
|
|
||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</>)
|
</>)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [textRender, currentExercise, changedPrompt]);
|
}, [textRender, currentExercise, changedPrompt]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user