ENCOA-253, ENCOA-248, ENCOA-246

This commit is contained in:
Carlos-Mesquita
2024-12-02 17:16:12 +00:00
parent cd14ac537d
commit 490c5ad7d3
8 changed files with 90 additions and 51 deletions

View File

@@ -112,7 +112,7 @@ const SettingsEditor: React.FC<SettingsEditorProps> = ({
onChange={(o) => onIntroOptionChange({ value: o!.value, label: o!.label })}
value={localSettings.introOption}
/>
{localSettings.introOption.value !== "None" && (
{localSettings.introOption && localSettings.introOption.value !== "None" && (
<AutoExpandingTextArea
key={`section-${sectionId}`}
value={localSettings.currentIntro || ''}

View File

@@ -33,21 +33,24 @@ const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => {
importModule
} = useExamEditorStore(state => state.modules[currentModule]);
const [numberOfLevelParts, setNumberOfLevelParts] = useState(levelParts !== undefined ? levelParts : 1);
const [numberOfLevelParts, setNumberOfLevelParts] = useState(levelParts !== 0 ? levelParts : 1);
useEffect(() => {
setNumberOfLevelParts(levelParts);
dispatch({
type: 'UPDATE_MODULE',
payload: {
updates: {
sectionLabels: Array.from({ length: levelParts }).map((_, i) => ({
id: i + 1,
label: `Part ${i + 1}`
}))
if (levelParts !== 0) {
setNumberOfLevelParts(levelParts);
dispatch({
type: 'UPDATE_MODULE',
payload: {
updates: {
sectionLabels: Array.from({ length: levelParts }).map((_, i) => ({
id: i + 1,
label: `Part ${i + 1}`
}))
},
module: "level"
}
}
})
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [levelParts])

View File

@@ -2,8 +2,9 @@ import Button from "@/components/Low/Button";
import Modal from "@/components/Modal";
import { Exam, LevelExam, MultipleChoiceExercise, ShuffleMap } from "@/interfaces/exam";
import useExamStore, { usePersistentExamStore } from "@/stores/exam";
import { defaultExamUserSolutions } from "@/utils/exams";
import clsx from "clsx";
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { BsFillGrid3X3GapFill } from "react-icons/bs";
interface Props {
@@ -18,7 +19,7 @@ const MCQuestionGrid: React.FC<Props> = ({ exam, showSolutions, runOnClick, prev
const examState = useExamStore((state) => state);
const persistentExamState = usePersistentExamStore((state) => state);
const {
userSolutions,
partIndex: sectionIndex,
@@ -27,7 +28,10 @@ const MCQuestionGrid: React.FC<Props> = ({ exam, showSolutions, runOnClick, prev
const currentExercise = useMemo(() => (exam as LevelExam).parts[sectionIndex!].exercises[exerciseIndex] as MultipleChoiceExercise, [exam, exerciseIndex, sectionIndex])
const userSolution = useMemo(() => userSolutions!.find((x) => x.exercise.toString() == currentExercise.id.toString())!, [currentExercise.id, userSolutions])
const answeredQuestions = useMemo(() => new Set(userSolution.solutions.map(sol => sol.question.toString())), [userSolution.solutions])
const answeredQuestions = useMemo(() =>
userSolution ? new Set(userSolution.solutions.map(sol => sol.question.toString())) : new Set(),
[userSolution]
);
const exerciseOffset = useMemo(() => Number(currentExercise.questions[0].id), [currentExercise.questions])
const lastExercise = useMemo(() => exerciseOffset + (currentExercise.questions.length - 1),
[currentExercise.questions.length, exerciseOffset]);

View File

@@ -8,29 +8,38 @@ import { LevelExam, ListeningExam, ReadingExam, SpeakingExam, WritingExam } from
import { User } from "@/interfaces/user";
import { usePersistentExamStore } from "@/stores/exam";
import clsx from "clsx";
import { useEffect } from "react";
// TODO: perms
const Popout: React.FC<{ user: User }> = ({ user }) => {
const state = usePersistentExamStore((state) => state);
const { bgColor, exam, partIndex, setUserSolutions } = usePersistentExamStore();
usePersistentStorage(usePersistentExamStore);
useEffect(() => {
return () => {
setUserSolutions([]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<div className={`relative flex w-full min-h-screen p-4 shadow-md items-center rounded-2xl ${state.bgColor}`}>
<div className={`relative flex w-full min-h-screen p-4 shadow-md items-center rounded-2xl ${bgColor}`}>
<div className={clsx("relative flex p-20 justify-center flex-1")}>
{state.exam?.module == "level" && state.exam.parts && state.partIndex >= 0 &&
<Level exam={state.exam as LevelExam} preview={true} />
{exam?.module == "level" && exam.parts && partIndex >= 0 &&
<Level exam={exam as LevelExam} preview={true} />
}
{state.exam?.module == "writing" && state.exam.exercises && state.partIndex >= 0 &&
<Writing exam={state.exam as WritingExam} preview={true} />
{exam?.module == "writing" && exam.exercises && partIndex >= 0 &&
<Writing exam={exam as WritingExam} preview={true} />
}
{state.exam?.module == "reading" && state.exam.parts.length > 0 &&
<Reading exam={state.exam as ReadingExam} preview={true} />
{exam?.module == "reading" && exam.parts.length > 0 &&
<Reading exam={exam as ReadingExam} preview={true} />
}
{state.exam?.module == "listening" && state.exam.parts.length > 0 &&
<Listening exam={state.exam as ListeningExam} preview={true} />
{exam?.module == "listening" && exam.parts.length > 0 &&
<Listening exam={exam as ListeningExam} preview={true} />
}
{state.exam?.module == "speaking" && state.exam.exercises.length > 0 &&
<Speaking exam={state.exam as SpeakingExam} preview={true} />
{exam?.module == "speaking" && exam.exercises.length > 0 &&
<Speaking exam={exam as SpeakingExam} preview={true} />
}
</div>
</div>