import {infoButtonStyle} from "@/constants/buttonStyles"; import {WritingExam} from "@/interfaces/exam"; import clsx from "clsx"; import {Fragment, useEffect, useState} from "react"; import {toast} from "react-toastify"; interface Props { exam: WritingExam; } export default function Writing({exam}: Props) { const [inputText, setInputText] = useState(""); const [isSubmitEnabled, setIsSubmitEnabled] = useState(false); const [timer, setTimer] = useState(); useEffect(() => { setTimer(exam.minTimer * 60); const timerInterval = setInterval(() => setTimer((prev) => prev && prev - 1), 1000); return () => { clearInterval(timerInterval); }; }, [exam.minTimer]); useEffect(() => { const words = inputText.split(" ").filter((x) => x !== ""); const {wordCounter} = exam.text; if (wordCounter.type === "min") { setIsSubmitEnabled(wordCounter.limit <= words.length); } else { setIsSubmitEnabled(true); if (wordCounter.limit < words.length) { toast.warning(`You have reached your word limit of ${wordCounter.limit} words!`); setInputText(words.slice(0, words.length - 1).join(" ")); } } }, [inputText, exam]); return (
{timer && (
{Math.floor(timer / 60) < 10 ? "0" : ""} {Math.floor(timer / 60)}:{timer % 60 < 10 ? "0" : ""} {timer % 60}
)}
{exam.text.info} {exam.text.prompt.split("\n").map((line, index) => ( {line}
))}
You should write {exam.text.wordCounter.type === "min" ? "at least" : "at most"} {exam.text.wordCounter.limit} words.