From bd0fab4c8ffb827e2de3c165f257ca9fb0db9bce Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Tue, 23 Jan 2024 11:45:32 +0000 Subject: [PATCH] Updated and fixed part of the partial test generation --- public/audio/error.mp3 | Bin 0 -> 13293 bytes src/pages/(generation)/LevelGeneration.tsx | 4 ++-- src/pages/(generation)/ListeningGeneration.tsx | 15 +++++++++++---- src/pages/(generation)/ReadingGeneration.tsx | 3 ++- src/pages/(generation)/SpeakingGeneration.tsx | 3 ++- src/pages/(generation)/WritingGeneration.tsx | 3 ++- src/utils/exams.be.ts | 2 +- src/utils/sound.ts | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 public/audio/error.mp3 diff --git a/public/audio/error.mp3 b/public/audio/error.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..8e3f03a76cd41c7fe1ef643ec4902cd71123d719 GIT binary patch literal 13293 zcmeHNc{r49+rMWu!x)31A*#{kzWdynpvxm${J!6j(Jm zhpk(Uxt{_60I~82_tn%^)6`NUlgQtC|MtfD?C^)$kBiR!dv|ktxG;b{0BEoQ7!Q&U zg+gP5u%eor}AFSlE&1r1YGe{F17gy1HxEe`##I z#csac*4BQvtGoMtZ~udb4~HL(JbgMk{$gTs^7ZuFnVGqT_aBy)mRG)VR%gPUvln;H zT9nnwuSS5X{H>_L{#Y6Jk@Fer4G7EvfIqht0Ra4X0041cMcgX4NTCA&)JoslSVK)$ zS54FLAMKxZIy$c6OZ^M{e+2zQ%b&p4`-|~i|6=@zzZgI3FUGI^i}CyZV*Ig_|J?uo z;En%S{1g896aW889)HUZKl%B8!w)aTCHI4?sr;=ah6G~XTo3smMIk?RJ0T?>M2R>C zFK!G(>}~u-b>8AM$25uLnFLzR|Nm-zk$K0J_14Aeyk`b*VP^g`DUCea|9>ch%R>Xqu z?D~pJ+}hBAh${Ot_!1P6w9UXM@1wJ?O$w&k$~p>qwwqs*)W1mUz6NE;$mVnqd_YPu zf}tC}nw%F6R*HMn_rys-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T1lmc(_K8}E;js<~oJ2C3FpF2ME;N7YAZ6fpDw#kez2a{+ zBM!}~_8uXe35i9S=>o)jbVbpQ`B^slhD%c(zBNV^rry?-?GXPwLI9sd87CT#UQiOU zh-er6u=qmKfh;%fhj3YbcdF`o#d#H>!tJE{r))`2D++dGbn*>caA*(->)<}%z@4{N z+=oA#pK{;N=B;bIG5ZbzCI z5nTD`j)BXtga(`GjOCU$LhtPzF=t%*--m4ScT{;T82LhT`zrtMq82ZhclSs9_Wy$j zW=8jt&+F0e`M;M>rbd2fPyQrEMx>%=*4al^-z*=fm=mdpX|g7yF?FmSaqc{j8kfzt z;6+DVe*x1kZ9-hnRmhemKZ_Fg_ml!(81zp_g7I68GklbU!2R|i!~m!NK*^&y^|CaR@_-y(EK*j!|a4wCf2Dr z`358GQfIdGqoou^VM8_RZHe^T&`fB52& zjos4`RzuuF2(#RP6bYHru6()5{}wh^JY3F5fSpl@=!vYEnbZ&}h8Uz+5>ZBfAz|0x~Tz zupfm>-x<2^V#brokoy?%I`$4By|c50S)6gFTUx;I>L4yT!S-e9h4d?|3u@8!=00R= zv-ewsY-y*T9tbkc9~OIKG;y*zy(1#L>_LIKnTa~&{x#Rd%L{Hf%MWu zUZR}*d~15kGKVXmITwE!yuZ?!TN>WE?rLy_Hz4GLH3P7`0L0+T!?Cy8{o!jrEGl^g37*aTee6H(XaCkx)xV~lD)-yzT%uET8wFl@hcm*BM z`R@PUe)r$R|EtHY?oYiqIg0~PA^6n|qi_BLxWiXaF{|fuzQylznsJ$%5$cs%jH zH2-h=*MHm}=G-9}fJr@n75* ze&YXjIP_P>{_gW9KR@~TJBRq+m7nqTAM2~1`r+I8$^Y$H-|9c}&tIH>e#rXojsG$K YzeD}7^b`MwwEWiilb_$H_+jCH08mt@xBvhE literal 0 HcmV?d00001 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`],