Updated the module generation to allow for only certain parts to be made

This commit is contained in:
Tiago Ribeiro
2024-01-22 18:50:12 +00:00
parent c868ea8795
commit 81943dbf42
5 changed files with 64 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
import Input from "@/components/Low/Input";
import {WritingExam} from "@/interfaces/exam";
import {WritingExam, WritingExercise} from "@/interfaces/exam";
import useExamStore from "@/stores/examStore";
import {getExamById} from "@/utils/exams";
import {playSound} from "@/utils/sound";
@@ -68,6 +68,7 @@ const TaskTab = ({task, index, setTask}: {task?: string; index: number; setTask:
const WritingGeneration = () => {
const [task1, setTask1] = useState<string>();
const [task2, setTask2] = useState<string>();
const [minTimer, setMinTimer] = useState(60);
const [isLoading, setIsLoading] = useState(false);
const [resultingExam, setResultingExam] = useState<WritingExam>();
@@ -93,18 +94,13 @@ const WritingGeneration = () => {
};
const submitExam = () => {
if (!task1 || !task2) {
toast.error("Please generate all tasks before submitting");
if (!task1 && !task2) {
toast.error("Please generate a task before submitting");
return;
}
setIsLoading(true);
const exam: WritingExam = {
isDiagnostic: false,
minTimer: 60,
module: "writing",
exercises: [
{
const exercise1 = task1
? ({
id: v4(),
type: "writing",
prefix: `You should spend about 20 minutes on this task.`,
@@ -115,8 +111,11 @@ const WritingGeneration = () => {
limit: 150,
type: "min",
},
},
{
} as WritingExercise)
: undefined;
const exercise2 = task2
? ({
id: v4(),
type: "writing",
prefix: `You should spend about 40 minutes on this task.`,
@@ -127,9 +126,17 @@ const WritingGeneration = () => {
limit: 250,
type: "min",
},
},
],
} as WritingExercise)
: undefined;
setIsLoading(true);
const exam: WritingExam = {
isDiagnostic: false,
minTimer,
module: "writing",
exercises: [...(exercise1 ? [exercise1] : []), ...(exercise2 ? [exercise2] : [])],
id: v4(),
variant: exercise1 && exercise2 ? "full" : "partial",
};
axios
@@ -152,6 +159,11 @@ const WritingGeneration = () => {
return (
<>
<div className="flex flex-col gap-3">
<label className="font-normal text-base text-mti-gray-dim">Timer</label>
<Input type="number" name="minTimer" onChange={(e) => setMinTimer(parseInt(e))} value={minTimer} className="max-w-[300px]" />
</div>
<Tab.Group>
<Tab.List className="flex space-x-1 rounded-xl bg-ielts-writing/20 p-1">
<Tab
@@ -200,14 +212,14 @@ const WritingGeneration = () => {
</button>
)}
<button
disabled={!task1 || !task2 || isLoading}
disabled={(!task1 && !task2) || isLoading}
data-tip="Please generate all three passages"
onClick={submitExam}
className={clsx(
"bg-ielts-writing/70 border border-ielts-writing text-white w-full max-w-[200px] rounded-xl h-[70px] self-end",
"hover:bg-ielts-writing disabled:bg-ielts-writing/40 disabled:cursor-not-allowed",
"transition ease-in-out duration-300",
(!task1 || !task2) && "tooltip",
!task1 && !task2 && "tooltip",
)}>
{isLoading ? (
<div className="flex items-center justify-center">