From 81943dbf424030f8d2f854dd8047d21984a0cbf5 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Mon, 22 Jan 2024 18:50:12 +0000 Subject: [PATCH] Updated the module generation to allow for only certain parts to be made --- src/interfaces/exam.ts | 2 +- .../(generation)/ListeningGeneration.tsx | 15 +++++-- src/pages/(generation)/ReadingGeneration.tsx | 20 ++++++--- src/pages/(generation)/SpeakingGeneration.tsx | 14 ++++-- src/pages/(generation)/WritingGeneration.tsx | 44 ++++++++++++------- 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/interfaces/exam.ts b/src/interfaces/exam.ts index ee08f0f5..b8e12632 100644 --- a/src/interfaces/exam.ts +++ b/src/interfaces/exam.ts @@ -1,7 +1,7 @@ import {Module} from "."; export type Exam = ReadingExam | ListeningExam | WritingExam | SpeakingExam | LevelExam; -export type Variant = "diagnostic" | "partial"; +export type Variant = "full" | "diagnostic" | "partial"; export interface ReadingExam { parts: ReadingPart[]; diff --git a/src/pages/(generation)/ListeningGeneration.tsx b/src/pages/(generation)/ListeningGeneration.tsx index bb74f6ca..c2d26237 100644 --- a/src/pages/(generation)/ListeningGeneration.tsx +++ b/src/pages/(generation)/ListeningGeneration.tsx @@ -110,6 +110,7 @@ const ListeningGeneration = () => { const [part2, setPart2] = useState(); const [part3, setPart3] = useState(); const [part4, setPart4] = useState(); + const [minTimer, setMinTimer] = useState(60); const [isLoading, setIsLoading] = useState(false); const [resultingExam, setResultingExam] = useState(); const [types, setTypes] = useState([]); @@ -129,12 +130,13 @@ const ListeningGeneration = () => { const toggleType = (type: string) => setTypes((prev) => (prev.includes(type) ? [...prev.filter((x) => x !== type)] : [...prev, type])); const submitExam = () => { - if (!part1 || !part2 || !part3 || !part4) return toast.error("Please generate all for sections!"); + const parts = [part1, part2, part3, part4].filter((x) => !!x); + if (parts.length === 0) return toast.error("Please generate at least one section!"); setIsLoading(true); axios - .post(`/api/exam/listening/generate/listening`, {parts: [part1, part2, part3, part4]}) + .post(`/api/exam/listening/generate/listening`, {parts, minTimer}) .then((result) => { playSound("sent"); console.log(`Generated Exam ID: ${result.data.id}`); @@ -172,6 +174,11 @@ const ListeningGeneration = () => { return ( <> +
+ + setMinTimer(parseInt(e))} value={minTimer} className="max-w-[300px]" /> +
+
@@ -264,14 +271,14 @@ const ListeningGeneration = () => { )} )} )} )}