/* eslint-disable @next/next/no-img-element */ import {errorButtonStyle, infoButtonStyle} from "@/constants/buttonStyles"; import {WritingExercise} from "@/interfaces/exam"; import {mdiArrowLeft, mdiArrowRight} from "@mdi/js"; import Icon from "@mdi/react"; import clsx from "clsx"; import {CommonProps} from "."; import {Fragment, useEffect, useState} from "react"; import {toast} from "react-toastify"; export default function Writing({id, prompt, info, type, wordCounter, attachment, onNext, onBack}: WritingExercise & CommonProps) { const [inputText, setInputText] = useState(""); const [isSubmitEnabled, setIsSubmitEnabled] = useState(false); useEffect(() => { const words = inputText.split(" ").filter((x) => x !== ""); 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!`, {toastId: "word-limit"}); setInputText(words.slice(0, words.length - 1).join(" ")); } } }, [inputText, wordCounter]); return (
{info} {prompt.split("\\n").map((line, index) => ( {line}
))}
You should write {wordCounter.type === "min" ? "at least" : "at most"} {wordCounter.limit} words. {attachment && Exercise attachment}