import {ReadingExam, UserSolution} from "@/interfaces/exam"; import {Fragment, useEffect, useState} from "react"; import Icon from "@mdi/react"; import {mdiArrowRight, mdiNotebook} from "@mdi/js"; import clsx from "clsx"; import {infoButtonStyle} from "@/constants/buttonStyles"; import {Dialog, Transition} from "@headlessui/react"; import {renderExercise} from "@/components/Exercises"; import {renderSolution} from "@/components/Solutions"; import {Panel} from "primereact/panel"; import {Steps} from "primereact/steps"; interface Props { exam: ReadingExam; showSolutions?: boolean; onFinish: (userSolutions: UserSolution[]) => void; } function TextModal({isOpen, title, content, onClose}: {isOpen: boolean; title: string; content: string; onClose: () => void}) { return ( {title} {content.split("\\n").map((line, index) => ( {line} ))} Got it, thanks! ); } export default function Reading({exam, showSolutions = false, onFinish}: Props) { const [exerciseIndex, setExerciseIndex] = useState(-1); const [showTextModal, setShowTextModal] = useState(false); const [userSolutions, setUserSolutions] = useState([]); const nextExercise = (solution?: UserSolution) => { if (solution) { setUserSolutions((prev) => [...prev.filter((x) => x.id !== solution.id), solution]); } if (exerciseIndex + 1 < exam.exercises.length) { setExerciseIndex((prev) => prev + 1); return; } if (solution) { onFinish([...userSolutions.filter((x) => x.id !== solution.id), solution].map((x) => ({...x, module: "reading", exam: exam.id}))); } else { onFinish(userSolutions.map((x) => ({...x, module: "reading", exam: exam.id}))); } }; const previousExercise = () => { setExerciseIndex((prev) => prev - 1); }; const renderText = () => ( Please read the following excerpt attentively, you will then be asked questions about the text you've read. You will be allowed to read the text while doing the exercises {exam.text.content.split("\\n").map((line, index) => ( {line} ))} ); return ( <> setShowTextModal(false)} /> {exerciseIndex === -1 && renderText()} {exerciseIndex > -1 && exerciseIndex < exam.exercises.length && !showSolutions && renderExercise(exam.exercises[exerciseIndex], nextExercise, previousExercise)} {exerciseIndex > -1 && exerciseIndex < exam.exercises.length && showSolutions && renderSolution(exam.exercises[exerciseIndex], nextExercise, previousExercise)} -1 ? "w-full justify-center md:justify-between" : "self-end w-full md:w-fit flex")}> {exerciseIndex > -1 && ( setShowTextModal(true)}> Read Text )} {exerciseIndex === -1 && ( nextExercise()}> Next )} > ); }
{content.split("\\n").map((line, index) => ( {line} ))}
{exam.text.content.split("\\n").map((line, index) => (
{line}