diff --git a/public/audio/error.mp3 b/public/audio/error.mp3 new file mode 100644 index 00000000..8e3f03a7 Binary files /dev/null and b/public/audio/error.mp3 differ diff --git a/src/pages/(generation)/LevelGeneration.tsx b/src/pages/(generation)/LevelGeneration.tsx index 1b02373d..26edda23 100644 --- a/src/pages/(generation)/LevelGeneration.tsx +++ b/src/pages/(generation)/LevelGeneration.tsx @@ -19,8 +19,8 @@ const TaskTab = ({exam, setExam}: {exam?: LevelExam; setExam: (exam: LevelExam) axios .get(`/api/exam/level/generate/level`) .then((result) => { - playSound("check"); - console.log(result.data); + playSound(typeof result.data === "string" ? "error" : "check"); + if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again."); setExam(result.data); }) .catch((error) => { diff --git a/src/pages/(generation)/ListeningGeneration.tsx b/src/pages/(generation)/ListeningGeneration.tsx index b77d6266..d45d7f98 100644 --- a/src/pages/(generation)/ListeningGeneration.tsx +++ b/src/pages/(generation)/ListeningGeneration.tsx @@ -26,7 +26,8 @@ const PartTab = ({part, types, index, setPart}: {part?: ListeningPart; types: st axios .get(`/api/exam/listening/generate/listening_section_${index}${topic || types ? `?${url.toString()}` : ""}`) .then((result) => { - playSound("check"); + playSound(typeof result.data === "string" ? "error" : "check"); + if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again."); setPart(result.data); }) .catch((error) => { @@ -110,14 +111,19 @@ const ListeningGeneration = () => { const [part2, setPart2] = useState(); const [part3, setPart3] = useState(); const [part4, setPart4] = useState(); - const [minTimer, setMinTimer] = useState(60); + const [minTimer, setMinTimer] = useState(30); const [isLoading, setIsLoading] = useState(false); const [resultingExam, setResultingExam] = useState(); const [types, setTypes] = useState([]); useEffect(() => { - const parts = [part1, part2, part3, part4].filter((x) => !!x); - setMinTimer(parts.length === 0 ? 60 : parts.length * 15); + const part1Timer = part1 ? 5 : 0; + const part2Timer = part2 ? 8 : 0; + const part3Timer = part3 ? 8 : 0; + const part4Timer = part4 ? 9 : 0; + + const sum = part1Timer + part2Timer + part3Timer + part4Timer; + setMinTimer(sum > 0 ? sum : 5); }, [part1, part2, part3, part4]); const availableTypes = [ @@ -136,6 +142,7 @@ const ListeningGeneration = () => { const submitExam = () => { const parts = [part1, part2, part3, part4].filter((x) => !!x); + console.log({parts}); if (parts.length === 0) return toast.error("Please generate at least one section!"); setIsLoading(true); diff --git a/src/pages/(generation)/ReadingGeneration.tsx b/src/pages/(generation)/ReadingGeneration.tsx index 87a33adf..54b25b3c 100644 --- a/src/pages/(generation)/ReadingGeneration.tsx +++ b/src/pages/(generation)/ReadingGeneration.tsx @@ -27,7 +27,8 @@ const PartTab = ({part, types, index, setPart}: {part?: ReadingPart; types: stri axios .get(`/api/exam/reading/generate/reading_passage_${index}${topic || types ? `?${url.toString()}` : ""}`) .then((result) => { - playSound("check"); + playSound(typeof result.data === "string" ? "error" : "check"); + if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again."); setPart(result.data); }) .catch((error) => { diff --git a/src/pages/(generation)/SpeakingGeneration.tsx b/src/pages/(generation)/SpeakingGeneration.tsx index aca2bbe0..b8d41069 100644 --- a/src/pages/(generation)/SpeakingGeneration.tsx +++ b/src/pages/(generation)/SpeakingGeneration.tsx @@ -21,7 +21,8 @@ const PartTab = ({part, index, setPart}: {part?: SpeakingPart; index: number; se axios .get(`/api/exam/speaking/generate/speaking_task_${index}`) .then((result) => { - playSound("check"); + playSound(typeof result.data === "string" ? "error" : "check"); + if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again."); setPart(result.data); }) .catch((error) => { diff --git a/src/pages/(generation)/WritingGeneration.tsx b/src/pages/(generation)/WritingGeneration.tsx index 734f3455..9f60813a 100644 --- a/src/pages/(generation)/WritingGeneration.tsx +++ b/src/pages/(generation)/WritingGeneration.tsx @@ -20,7 +20,8 @@ const TaskTab = ({task, index, setTask}: {task?: string; index: number; setTask: axios .get(`/api/exam/writing/generate/writing_task${index}_general`) .then((result) => { - playSound("check"); + playSound(typeof result.data === "string" ? "error" : "check"); + if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again."); setTask(result.data.question); }) .catch((error) => { diff --git a/src/utils/exams.be.ts b/src/utils/exams.be.ts index 61d939b4..b6d15244 100644 --- a/src/utils/exams.be.ts +++ b/src/utils/exams.be.ts @@ -46,6 +46,6 @@ export const getExams = async ( }; const filterByVariant = (exams: Exam[], variant?: Variant) => { - const filtered = variant && variant === "partial" ? exams.filter((x) => x.variant === "partial") : exams; + const filtered = variant && variant === "partial" ? exams.filter((x) => x.variant === "partial") : exams.filter((x) => x.variant !== "partial"); return filtered.length > 0 ? filtered : exams; }; diff --git a/src/utils/sound.ts b/src/utils/sound.ts index d4bc5a84..cc932a62 100644 --- a/src/utils/sound.ts +++ b/src/utils/sound.ts @@ -1,6 +1,6 @@ import {Howl, Howler} from "howler"; -export type Sound = "check" | "sent"; +export type Sound = "check" | "sent" | "error"; export const playSound = (path: Sound) => { const sound = new Howl({ src: [`audio/${path}.mp3`],