Added Fill Blanks Edits + True False Edit

This commit is contained in:
Joao Ramos
2024-07-03 11:13:13 +01:00
parent 5cfd6d56a6
commit c9daba17e1
9 changed files with 610 additions and 278 deletions

View File

@@ -0,0 +1,84 @@
import { FillBlanksExercise } from "@/interfaces/exam";
import React from "react";
import Input from "@/components/Low/Input";
interface Props {
exercise: FillBlanksExercise;
updateExercise: (data: any) => void;
}
const FillBlanksEdit = (props: Props) => {
const { exercise, updateExercise } = props;
return (
<>
<Input
type="text"
label="Prompt"
name="prompt"
required
value={exercise.prompt}
onChange={(value) =>
updateExercise({
prompt: value,
})
}
/>
<Input
type="text"
label="Text"
name="text"
required
value={exercise.text}
onChange={(value) =>
updateExercise({
text: value,
})
}
/>
<h1>Solutions</h1>
<div className="w-full flex flex-wrap -mx-2">
{exercise.solutions.map((solution, index) => (
<div key={solution.id} className="flex sm:w-1/2 lg:w-1/4 px-2">
<Input
type="text"
label={`Solution ${index + 1}`}
name="solution"
required
value={solution.solution}
onChange={(value) =>
updateExercise({
solutions: exercise.solutions.map((sol) =>
sol.id === solution.id ? { ...sol, solution: value } : sol
),
})
}
/>
</div>
))}
</div>
<h1>Words</h1>
<div className="w-full flex flex-wrap -mx-2">
{exercise.words.map((word, index) => (
<div key={index} className="flex sm:w-1/2 lg:w-1/4 px-2">
<Input
type="text"
label={`Word ${index + 1}`}
name="word"
required
value={word}
onChange={(value) =>
updateExercise({
words: exercise.words.map((sol, idx) =>
index === idx ? value : sol
),
})
}
/>
</div>
))}
</div>
</>
);
};
export default FillBlanksEdit;

View File

@@ -0,0 +1,7 @@
import React from "react";
const InteractiveSpeakingEdit = () => {
return null;
};
export default InteractiveSpeakingEdit;

View File

@@ -0,0 +1,7 @@
import React from 'react';
const MatchSentencesEdit = () => {
return null;
}
export default MatchSentencesEdit;

View File

@@ -0,0 +1,7 @@
import React from 'react';
const MultipleChoiceEdit = () => {
return null;
}
export default MultipleChoiceEdit;

View File

@@ -0,0 +1,7 @@
import React from 'react';
const SpeakingEdit = () => {
return null;
}
export default SpeakingEdit;

View File

@@ -0,0 +1,71 @@
import React from "react";
import { TrueFalseExercise } from "@/interfaces/exam";
import Input from "@/components/Low/Input";
import Select from "@/components/Low/Select";
interface Props {
exercise: TrueFalseExercise;
updateExercise: (data: any) => void;
}
const options = [
{ value: "true", label: "True" },
{ value: "false", label: "False" },
{ value: "not_given", label: "Not Given" },
];
const TrueFalseEdit = (props: Props) => {
const { exercise, updateExercise } = props;
return (
<>
<Input
type="text"
label="Prompt"
name="prompt"
required
value={exercise.prompt}
onChange={(value) =>
updateExercise({
prompt: value,
})
}
/>
<h1>Questions</h1>
<div className="w-full flex-no-wrap -mx-2">
{exercise.questions.map((question, index) => (
<div key={question.id} className="flex w-full px-2">
<Input
type="text"
label={`Question ${index + 1}`}
name="question"
required
value={question.prompt}
onChange={(value) =>
updateExercise({
questions: exercise.questions.map((sol) =>
sol.id === question.id ? { ...sol, prompt: value } : sol
),
})
}
/>
<div className="w-48 flex items-end px-2">
<Select
value={options.find((o) => o.value === question.solution)}
options={options}
onChange={(value) => {
updateExercise({
questions: exercise.questions.map((sol) =>
sol.id === question.id ? { ...sol, solution: value?.value } : sol
),
});
}}
className="h-18"
/>
</div>
</div>
))}
</div>
</>
);
};
export default TrueFalseEdit;

View File

@@ -0,0 +1,7 @@
import React from 'react';
const WhiteBlankEdits = () => {
return null;
}
export default WhiteBlankEdits;

View File

@@ -0,0 +1,7 @@
import React from 'react';
const WritingEdit = () => {
return null;
}
export default WritingEdit;

View File

@@ -1,315 +1,450 @@
import Input from "@/components/Low/Input"; import Input from "@/components/Low/Input";
import Select from "@/components/Low/Select"; import Select from "@/components/Low/Select";
import {Difficulty, ReadingExam, ReadingPart} from "@/interfaces/exam"; import {
Difficulty,
Exercise,
ReadingExam,
ReadingPart,
} from "@/interfaces/exam";
import useExamStore from "@/stores/examStore"; import useExamStore from "@/stores/examStore";
import {getExamById} from "@/utils/exams"; import { getExamById } from "@/utils/exams";
import {playSound} from "@/utils/sound"; import { playSound } from "@/utils/sound";
import {convertCamelCaseToReadable} from "@/utils/string"; import { convertCamelCaseToReadable } from "@/utils/string";
import {Tab} from "@headlessui/react"; import { Tab } from "@headlessui/react";
import axios from "axios"; import axios from "axios";
import clsx from "clsx"; import clsx from "clsx";
import {capitalize, sample} from "lodash"; import { capitalize, sample } from "lodash";
import {useRouter} from "next/router"; import { useRouter } from "next/router";
import {useEffect, useState} from "react"; import { useEffect, useState, Dispatch, SetStateAction } from "react";
import {BsArrowRepeat, BsCheck} from "react-icons/bs"; import { BsArrowRepeat, BsCheck } from "react-icons/bs";
import {toast} from "react-toastify"; import { toast } from "react-toastify";
import {v4} from "uuid"; import { v4 } from "uuid";
import FillBlanksEdit from "@/components/Generation/fill.blanks.edit";
import TrueFalseEdit from "@/components/Generation/true.false.edit";
const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"]; const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"];
const PartTab = ({ const PartTab = ({
part, part,
types, types,
difficulty, difficulty,
index, index,
setPart, setPart,
updatePart,
}: { }: {
part?: ReadingPart; part?: ReadingPart;
types: string[]; types: string[];
index: number; index: number;
difficulty: Difficulty; difficulty: Difficulty;
setPart: (part?: ReadingPart) => void; setPart: (part?: ReadingPart) => void;
updatePart: Dispatch<SetStateAction<ReadingPart | undefined>>;
// updatePart: (updater: (part: ReadingPart) => ReadingPart) => void;
}) => { }) => {
const [topic, setTopic] = useState(""); const [topic, setTopic] = useState("");
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const generate = () => { const generate = () => {
const url = new URLSearchParams(); const url = new URLSearchParams();
url.append("difficulty", difficulty); url.append("difficulty", difficulty);
if (topic) url.append("topic", topic); if (topic) url.append("topic", topic);
if (types) types.forEach((t) => url.append("exercises", t)); if (types) types.forEach((t) => url.append("exercises", t));
setPart(undefined); setPart(undefined);
setIsLoading(true); setIsLoading(true);
axios axios
.get(`/api/exam/reading/generate/reading_passage_${index}${topic || types ? `?${url.toString()}` : ""}`) .get(
.then((result) => { `/api/exam/reading/generate/reading_passage_${index}${
playSound(typeof result.data === "string" ? "error" : "check"); topic || types ? `?${url.toString()}` : ""
if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again."); }`
setPart(result.data); )
}) .then((result) => {
.catch((error) => { playSound(typeof result.data === "string" ? "error" : "check");
console.log(error); if (typeof result.data === "string")
toast.error("Something went wrong!"); return toast.error(
}) "Something went wrong, please try to generate again."
.finally(() => setIsLoading(false)); );
}; setPart(result.data);
})
.catch((error) => {
console.log(error);
toast.error("Something went wrong!");
})
.finally(() => setIsLoading(false));
};
return ( const renderExercises = () => {
<Tab.Panel className="w-full bg-ielts-reading/20 min-h-[600px] h-full rounded-xl p-6 flex flex-col gap-4"> return part?.exercises.map((exercise) => {
<div className="flex gap-4 items-end"> switch (exercise.type) {
<Input type="text" placeholder="Grand Canyon..." name="topic" label="Topic" onChange={setTopic} roundness="xl" defaultValue={topic} /> case "fillBlanks":
<button return (
onClick={generate} <>
disabled={isLoading || types.length === 0} <h1>Exercise: Fill Blanks</h1>
data-tip="The passage is currently being generated" <FillBlanksEdit
className={clsx( exercise={exercise}
"bg-ielts-reading/70 border border-ielts-reading text-white w-full max-w-[200px] rounded-xl h-[70px]", key={exercise.id}
"hover:bg-ielts-reading disabled:bg-ielts-reading/40 disabled:cursor-not-allowed", updateExercise={(data: any) =>
"transition ease-in-out duration-300", updatePart((part?: ReadingPart) => {
isLoading && "tooltip", if (part) {
)}> const exercises = part.exercises.map((x) =>
{isLoading ? ( x.id === exercise.id ? { ...x, ...data } : x
<div className="flex items-center justify-center"> ) as Exercise[];
<BsArrowRepeat className="text-white animate-spin" size={25} /> const updatedPart = { ...part, exercises } as ReadingPart;
</div> return updatedPart;
) : ( }
"Generate" })
)} }
</button> />
</div> </>
{isLoading && ( );
<div className="w-fit h-fit mt-12 self-center animate-pulse flex flex-col gap-8 items-center"> case "trueFalse":
<span className={clsx("loading loading-infinity w-32 text-ielts-reading")} /> return (
<span className={clsx("font-bold text-2xl text-ielts-reading")}>Generating...</span> <>
</div> <h1>Exercise: True or False</h1>
)} <TrueFalseEdit
{part && ( exercise={exercise}
<div className="flex flex-col gap-2 w-full overflow-y-scroll scrollbar-hide"> key={exercise.id}
<div className="flex gap-4"> updateExercise={(data: any) => {
{part.exercises.map((x) => ( updatePart((part?: ReadingPart) => {
<span className="rounded-xl bg-white border border-ielts-reading p-1 px-4" key={x.id}> if (part) {
{x.type && convertCamelCaseToReadable(x.type)} return {
</span> ...part,
))} exercises: part.exercises.map((x) =>
</div> x.id === exercise.id ? { ...x, ...data } : x
<h3 className="text-xl font-semibold">{part.text.title}</h3> ),
<span className="w-full h-96">{part.text.content}</span> } as ReadingPart;
</div> }
)} });
</Tab.Panel> }}
); />
</>
);
default:
return null;
}
});
};
return (
<Tab.Panel className="w-full bg-ielts-reading/20 min-h-[600px] h-full rounded-xl p-6 flex flex-col gap-4">
<div className="flex gap-4 items-end">
<Input
type="text"
placeholder="Grand Canyon..."
name="topic"
label="Topic"
onChange={setTopic}
roundness="xl"
defaultValue={topic}
/>
<button
onClick={generate}
disabled={isLoading || types.length === 0}
data-tip="The passage is currently being generated"
className={clsx(
"bg-ielts-reading/70 border border-ielts-reading text-white w-full max-w-[200px] rounded-xl h-[70px]",
"hover:bg-ielts-reading disabled:bg-ielts-reading/40 disabled:cursor-not-allowed",
"transition ease-in-out duration-300",
isLoading && "tooltip"
)}
>
{isLoading ? (
<div className="flex items-center justify-center">
<BsArrowRepeat className="text-white animate-spin" size={25} />
</div>
) : (
"Generate"
)}
</button>
</div>
{isLoading && (
<div className="w-fit h-fit mt-12 self-center animate-pulse flex flex-col gap-8 items-center">
<span
className={clsx("loading loading-infinity w-32 text-ielts-reading")}
/>
<span className={clsx("font-bold text-2xl text-ielts-reading")}>
Generating...
</span>
</div>
)}
{part && (
<>
<div className="flex flex-col gap-2 w-full overflow-y-scroll scrollbar-hide">
<div className="flex gap-4">
{part.exercises.map((x) => (
<span
className="rounded-xl bg-white border border-ielts-reading p-1 px-4"
key={x.id}
>
{x.type && convertCamelCaseToReadable(x.type)}
</span>
))}
</div>
<h3 className="text-xl font-semibold">{part.text.title}</h3>
<span className="w-full h-96">{part.text.content}</span>
</div>
{renderExercises()}
</>
)}
</Tab.Panel>
);
}; };
const ReadingGeneration = () => { const ReadingGeneration = () => {
const [part1, setPart1] = useState<ReadingPart>(); const [part1, setPart1] = useState<ReadingPart>();
const [part2, setPart2] = useState<ReadingPart>(); const [part2, setPart2] = useState<ReadingPart>();
const [part3, setPart3] = useState<ReadingPart>(); const [part3, setPart3] = useState<ReadingPart>();
const [minTimer, setMinTimer] = useState(60); const [minTimer, setMinTimer] = useState(60);
const [types, setTypes] = useState<string[]>([]); const [types, setTypes] = useState<string[]>([]);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [resultingExam, setResultingExam] = useState<ReadingExam>(); const [resultingExam, setResultingExam] = useState<ReadingExam>();
const [difficulty, setDifficulty] = useState<Difficulty>(sample(DIFFICULTIES)!); const [difficulty, setDifficulty] = useState<Difficulty>(
sample(DIFFICULTIES)!
);
useEffect(() => { useEffect(() => {
const parts = [part1, part2, part3].filter((x) => !!x); const parts = [part1, part2, part3].filter((x) => !!x);
setMinTimer(parts.length === 0 ? 60 : parts.length * 20); setMinTimer(parts.length === 0 ? 60 : parts.length * 20);
}, [part1, part2, part3]); }, [part1, part2, part3]);
const router = useRouter(); const router = useRouter();
const setExams = useExamStore((state) => state.setExams); const setExams = useExamStore((state) => state.setExams);
const setSelectedModules = useExamStore((state) => state.setSelectedModules); const setSelectedModules = useExamStore((state) => state.setSelectedModules);
const availableTypes = [ const availableTypes = [
{type: "fillBlanks", label: "Fill the Blanks"}, { type: "fillBlanks", label: "Fill the Blanks" },
{type: "trueFalse", label: "True or False"}, { type: "trueFalse", label: "True or False" },
{type: "writeBlanks", label: "Write the Blanks"}, { type: "writeBlanks", label: "Write the Blanks" },
{type: "matchSentences", label: "Match Sentences"}, { type: "matchSentences", label: "Match Sentences" },
]; ];
const toggleType = (type: string) => setTypes((prev) => (prev.includes(type) ? [...prev.filter((x) => x !== type)] : [...prev, type])); const toggleType = (type: string) =>
setTypes((prev) =>
prev.includes(type)
? [...prev.filter((x) => x !== type)]
: [...prev, type]
);
const loadExam = async (examId: string) => { const loadExam = async (examId: string) => {
const exam = await getExamById("reading", examId.trim()); const exam = await getExamById("reading", examId.trim());
if (!exam) { if (!exam) {
toast.error("Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID", { toast.error(
toastId: "invalid-exam-id", "Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID",
}); {
toastId: "invalid-exam-id",
}
);
return; return;
} }
setExams([exam]); setExams([exam]);
setSelectedModules(["reading"]); setSelectedModules(["reading"]);
router.push("/exercises"); router.push("/exercises");
}; };
const submitExam = () => { const submitExam = () => {
const parts = [part1, part2, part3].filter((x) => !!x) as ReadingPart[]; const parts = [part1, part2, part3].filter((x) => !!x) as ReadingPart[];
if (parts.length === 0) { if (parts.length === 0) {
toast.error("Please generate at least one passage before submitting"); toast.error("Please generate at least one passage before submitting");
return; return;
} }
setIsLoading(true); setIsLoading(true);
const exam: ReadingExam = { const exam: ReadingExam = {
parts, parts,
isDiagnostic: false, isDiagnostic: false,
minTimer, minTimer,
module: "reading", module: "reading",
id: v4(), id: v4(),
type: "academic", type: "academic",
variant: parts.length === 3 ? "full" : "partial", variant: parts.length === 3 ? "full" : "partial",
difficulty, difficulty,
}; };
axios axios
.post(`/api/exam/reading`, exam) .post(`/api/exam/reading`, exam)
.then((result) => { .then((result) => {
playSound("sent"); playSound("sent");
console.log(`Generated Exam ID: ${result.data.id}`); console.log(`Generated Exam ID: ${result.data.id}`);
toast.success("This new exam has been generated successfully! Check the ID in our browser's console."); toast.success(
setResultingExam(result.data); "This new exam has been generated successfully! Check the ID in our browser's console."
);
setResultingExam(result.data);
setPart1(undefined); setPart1(undefined);
setPart2(undefined); setPart2(undefined);
setPart3(undefined); setPart3(undefined);
setDifficulty(sample(DIFFICULTIES)!); setDifficulty(sample(DIFFICULTIES)!);
setMinTimer(60); setMinTimer(60);
setTypes([]); setTypes([]);
}) })
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);
toast.error("Something went wrong while generating, please try again later."); toast.error(
}) "Something went wrong while generating, please try again later."
.finally(() => setIsLoading(false)); );
}; })
.finally(() => setIsLoading(false));
};
return ( return (
<> <>
<div className="flex gap-4 w-1/2"> <div className="flex gap-4 w-1/2">
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
<label className="font-normal text-base text-mti-gray-dim">Timer</label> <label className="font-normal text-base text-mti-gray-dim">
<Input Timer
type="number" </label>
name="minTimer" <Input
onChange={(e) => setMinTimer(parseInt(e) < 15 ? 15 : parseInt(e))} type="number"
value={minTimer} name="minTimer"
className="max-w-[300px]" onChange={(e) => setMinTimer(parseInt(e) < 15 ? 15 : parseInt(e))}
/> value={minTimer}
</div> className="max-w-[300px]"
<div className="flex flex-col gap-3 w-full"> />
<label className="font-normal text-base text-mti-gray-dim">Difficulty</label> </div>
<Select <div className="flex flex-col gap-3 w-full">
options={DIFFICULTIES.map((x) => ({value: x, label: capitalize(x)}))} <label className="font-normal text-base text-mti-gray-dim">
onChange={(value) => (value ? setDifficulty(value.value as Difficulty) : null)} Difficulty
value={{value: difficulty, label: capitalize(difficulty)}} </label>
disabled={!!part1 || !!part2 || !!part3} <Select
/> options={DIFFICULTIES.map((x) => ({
</div> value: x,
</div> label: capitalize(x),
}))}
onChange={(value) =>
value ? setDifficulty(value.value as Difficulty) : null
}
value={{ value: difficulty, label: capitalize(difficulty) }}
disabled={!!part1 || !!part2 || !!part3}
/>
</div>
</div>
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
<label className="font-normal text-base text-mti-gray-dim">Exercises</label> <label className="font-normal text-base text-mti-gray-dim">
<div className="flex flex-row -2xl:flex-wrap w-full gap-4 -md:justify-center justify-between"> Exercises
{availableTypes.map((x) => ( </label>
<span <div className="flex flex-row -2xl:flex-wrap w-full gap-4 -md:justify-center justify-between">
onClick={() => toggleType(x.type)} {availableTypes.map((x) => (
key={x.type} <span
className={clsx( onClick={() => toggleType(x.type)}
"px-6 py-4 w-64 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer", key={x.type}
"transition duration-300 ease-in-out", className={clsx(
!types.includes(x.type) ? "bg-white border-mti-gray-platinum" : "bg-ielts-reading/70 border-ielts-reading text-white", "px-6 py-4 w-64 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
)}> "transition duration-300 ease-in-out",
{x.label} !types.includes(x.type)
</span> ? "bg-white border-mti-gray-platinum"
))} : "bg-ielts-reading/70 border-ielts-reading text-white"
</div> )}
</div> >
{x.label}
</span>
))}
</div>
</div>
<Tab.Group> <Tab.Group>
<Tab.List className="flex space-x-1 rounded-xl bg-ielts-reading/20 p-1"> <Tab.List className="flex space-x-1 rounded-xl bg-ielts-reading/20 p-1">
<Tab <Tab
className={({selected}) => className={({ selected }) =>
clsx( clsx(
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-reading/70 flex gap-2 items-center justify-center", "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-reading/70 flex gap-2 items-center justify-center",
"ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-reading focus:outline-none focus:ring-2", "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-reading focus:outline-none focus:ring-2",
"transition duration-300 ease-in-out", "transition duration-300 ease-in-out",
selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-reading", selected
) ? "bg-white shadow"
}> : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-reading"
Passage 1 {part1 && <BsCheck />} )
</Tab> }
<Tab >
className={({selected}) => Passage 1 {part1 && <BsCheck />}
clsx( </Tab>
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-reading/70 flex gap-2 items-center justify-center", <Tab
"ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-reading focus:outline-none focus:ring-2", className={({ selected }) =>
"transition duration-300 ease-in-out", clsx(
selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-reading", "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-reading/70 flex gap-2 items-center justify-center",
) "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-reading focus:outline-none focus:ring-2",
}> "transition duration-300 ease-in-out",
Passage 2 {part2 && <BsCheck />} selected
</Tab> ? "bg-white shadow"
<Tab : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-reading"
className={({selected}) => )
clsx( }
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-reading/70 flex gap-2 items-center justify-center", >
"ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-reading focus:outline-none focus:ring-2", Passage 2 {part2 && <BsCheck />}
"transition duration-300 ease-in-out", </Tab>
selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-reading", <Tab
) className={({ selected }) =>
}> clsx(
Passage 3 {part3 && <BsCheck />} "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-reading/70 flex gap-2 items-center justify-center",
</Tab> "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-reading focus:outline-none focus:ring-2",
</Tab.List> "transition duration-300 ease-in-out",
<Tab.Panels> selected
{[ ? "bg-white shadow"
{part: part1, setPart: setPart1}, : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-reading"
{part: part2, setPart: setPart2}, )
{part: part3, setPart: setPart3}, }
].map(({part, setPart}, index) => ( >
<PartTab part={part} types={types} difficulty={difficulty} index={index + 1} key={index} setPart={setPart} /> Passage 3 {part3 && <BsCheck />}
))} </Tab>
</Tab.Panels> </Tab.List>
</Tab.Group> <Tab.Panels>
<div className="w-full flex justify-end gap-4"> {[
{resultingExam && ( { part: part1, setPart: setPart1 },
<button { part: part2, setPart: setPart2 },
disabled={isLoading} { part: part3, setPart: setPart3 },
onClick={() => loadExam(resultingExam.id)} ].map(({ part, setPart }, index) => (
className={clsx( <PartTab
"bg-white border border-ielts-reading text-ielts-reading w-full max-w-[200px] rounded-xl h-[70px] self-end", part={part}
"hover:bg-ielts-reading hover:text-white disabled:bg-ielts-reading/40 disabled:cursor-not-allowed", types={types}
"transition ease-in-out duration-300", difficulty={difficulty}
)}> index={index + 1}
Perform Exam key={index}
</button> setPart={setPart}
)} updatePart={setPart}
<button />
disabled={(!part1 && !part2 && !part3) || isLoading} ))}
data-tip="Please generate all three passages" </Tab.Panels>
onClick={submitExam} </Tab.Group>
className={clsx( <div className="w-full flex justify-end gap-4">
"bg-ielts-reading/70 border border-ielts-reading text-white w-full max-w-[200px] rounded-xl h-[70px] self-end", {resultingExam && (
"hover:bg-ielts-reading disabled:bg-ielts-reading/40 disabled:cursor-not-allowed", <button
"transition ease-in-out duration-300", disabled={isLoading}
!part1 && !part2 && !part3 && "tooltip", onClick={() => loadExam(resultingExam.id)}
)}> className={clsx(
{isLoading ? ( "bg-white border border-ielts-reading text-ielts-reading w-full max-w-[200px] rounded-xl h-[70px] self-end",
<div className="flex items-center justify-center"> "hover:bg-ielts-reading hover:text-white disabled:bg-ielts-reading/40 disabled:cursor-not-allowed",
<BsArrowRepeat className="text-white animate-spin" size={25} /> "transition ease-in-out duration-300"
</div> )}
) : ( >
"Submit" Perform Exam
)} </button>
</button> )}
</div> <button
</> disabled={(!part1 && !part2 && !part3) || isLoading}
); data-tip="Please generate all three passages"
onClick={submitExam}
className={clsx(
"bg-ielts-reading/70 border border-ielts-reading text-white w-full max-w-[200px] rounded-xl h-[70px] self-end",
"hover:bg-ielts-reading disabled:bg-ielts-reading/40 disabled:cursor-not-allowed",
"transition ease-in-out duration-300",
!part1 && !part2 && !part3 && "tooltip"
)}
>
{isLoading ? (
<div className="flex items-center justify-center">
<BsArrowRepeat className="text-white animate-spin" size={25} />
</div>
) : (
"Submit"
)}
</button>
</div>
</>
);
}; };
export default ReadingGeneration; export default ReadingGeneration;