import {errorButtonStyle, infoButtonStyle} from "@/constants/buttonStyles"; import {MatchSentencesExercise} from "@/interfaces/exam"; import {mdiArrowLeft, mdiArrowRight} from "@mdi/js"; import Icon from "@mdi/react"; import clsx from "clsx"; import {Fragment, useEffect, useState} from "react"; import LineTo from "react-lineto"; import {CommonProps} from "."; import Button from "../Low/Button"; import Xarrow from "react-xarrows"; import useExamStore from "@/stores/examStore"; export default function MatchSentences({id, options, type, prompt, sentences, userSolutions, onNext, onBack}: MatchSentencesExercise & CommonProps) { const [selectedQuestion, setSelectedQuestion] = useState(); const [answers, setAnswers] = useState<{question: string; option: string}[]>(userSolutions); const hasExamEnded = useExamStore((state) => state.hasExamEnded); const calculateScore = () => { const total = sentences.length; const correct = answers.filter((x) => sentences.find((y) => y.id.toString() === x.question)?.solution === x.option || false).length; const missing = total - answers.filter((x) => sentences.find((y) => y.id.toString() === x.question)).length; return {total, correct, missing}; }; const selectOption = (option: string) => { if (!selectedQuestion) return; setAnswers((prev) => [...prev.filter((x) => x.question !== selectedQuestion), {question: selectedQuestion, option}]); setSelectedQuestion(undefined); }; useEffect(() => { if (hasExamEnded) onNext({exercise: id, solutions: answers, score: calculateScore(), type}); // eslint-disable-next-line react-hooks/exhaustive-deps }, [hasExamEnded]); return ( <>
{prompt.split("\\n").map((line, index) => ( {line}
))}
{sentences.map(({sentence, id}) => (
{sentence}
))}
{options.map(({sentence, id}) => (
{sentence}
))}
{answers.map((solution, index) => ( ))}
); }