import FillBlanksEdit from "@/components/Generation/fill.blanks.edit"; import MultipleChoiceEdit from "@/components/Generation/multiple.choice.edit"; import WriteBlankEdits from "@/components/Generation/write.blanks.edit"; import Checkbox from "@/components/Low/Checkbox"; import Input from "@/components/Low/Input"; import Select from "@/components/Low/Select"; import { Difficulty, LevelExam, MultipleChoiceExercise, MultipleChoiceQuestion, LevelPart, FillBlanksExercise, WriteBlanksExercise, Exercise, } from "@/interfaces/exam"; import useExamStore from "@/stores/examStore"; import { getExamById } from "@/utils/exams"; import { playSound } from "@/utils/sound"; import { Tab } from "@headlessui/react"; import axios from "axios"; import clsx from "clsx"; import { capitalize, sample } from "lodash"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { BsArrowRepeat, BsCheck, BsPencilSquare, BsX } from "react-icons/bs"; import reactStringReplace from "react-string-replace"; import { toast } from "react-toastify"; import { v4 } from "uuid"; interface Option { [key: string]: any; value: string | null; label: string; } const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"]; const TYPES: { [key: string]: string } = { multiple_choice_4: "Multiple Choice", multiple_choice_blank_space: "Multiple Choice - Blank Space", multiple_choice_underlined: "Multiple Choice - Underlined", blank_space_text: "Blank Space", reading_passage_utas: "Reading Passage", fill_blanks_mc: "Multiple Choice - Fill Blanks", }; type LevelSection = { type: string; quantity: number; topic?: string; part?: LevelPart }; const QuestionDisplay = ({ question, onUpdate }: { question: MultipleChoiceQuestion; onUpdate: (question: MultipleChoiceQuestion) => void }) => { const [isEditing, setIsEditing] = useState(false); const [options, setOptions] = useState(question.options); const [answer, setAnswer] = useState(question.solution); const renderPrompt = (prompt: string) => { return reactStringReplace(prompt, /(()[\w\s']+(<\/u>))/g, (match) => { const word = match.replaceAll("", "").replaceAll("", ""); return word.length > 0 ? {word} : null; }); }; return (
<> {question.id}. {renderPrompt(question.prompt).filter((x) => x?.toString() !== "")}
{question.options.map((option, index) => ( setAnswer(option.id)}> ({option.id}) {" "} {isEditing ? ( setOptions((prev) => prev.map((x, idx) => (idx === index ? { ...x, text: e.target.value } : x)))} /> ) : ( {option.text} )} ))}
{!isEditing && ( )} {isEditing && ( <> )}
); }; const TaskTab = ({ section, label, index, setSection }: { section: LevelSection; label: string, index: number, setSection: (section: LevelSection) => void }) => { const [isLoading, setIsLoading] = useState(false); const [category, setCategory] = useState(""); const [description, setDescription] = useState(""); const [customDescription, setCustomDescription] = useState(""); const [previousOption, setPreviousOption] = useState