Updated more of the exam generation

This commit is contained in:
Tiago Ribeiro
2023-11-20 23:30:47 +00:00
parent 4c7e8f56d8
commit cdc8cfe46e
6 changed files with 209 additions and 54 deletions

View File

@@ -8,14 +8,19 @@ import {useState} from "react";
import {BsArrowRepeat} from "react-icons/bs";
import {toast} from "react-toastify";
const PartTab = ({part, types, index, setPart}: {part?: ReadingPart; types: string[]; index: number; setPart: (part: ReadingPart) => void}) => {
const PartTab = ({part, types, index, setPart}: {part?: ReadingPart; types: string[]; index: number; setPart: (part?: ReadingPart) => void}) => {
const [topic, setTopic] = useState("");
const [isLoading, setIsLoading] = useState(false);
const generate = () => {
const url = new URLSearchParams();
if (topic) url.append("topic", topic);
if (types) types.forEach((t) => url.append("exercises", t));
setPart(undefined);
setIsLoading(true);
axios
.get(`/api/exam/reading/generate/reading_passage_${index}?topic=${topic}&exercises=${types.join("&exercises=")}`)
.get(`/api/exam/reading/generate/reading_passage_${index}${topic || types ? `?${url.toString()}` : ""}`)
.then((result) => setPart(result.data))
.catch((error) => {
console.log(error);
@@ -30,17 +35,13 @@ const PartTab = ({part, types, index, setPart}: {part?: ReadingPart; types: stri
<Input type="text" placeholder="Grand Canyon..." name="topic" label="Topic" onChange={setTopic} roundness="xl" defaultValue={topic} />
<button
onClick={generate}
disabled={types.length === 0 || topic.length === 0 || isLoading}
data-tip={
types.length === 0 || topic.length === 0
? "Please select at least one exercise type and write a topic"
: "The passage is currently being generated"
}
disabled={isLoading}
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",
(types.length === 0 || topic.length === 0 || isLoading) && "tooltip",
isLoading && "tooltip",
)}>
{isLoading ? (
<div className="flex items-center justify-center">