From 729204a095abac32e2abfcb99b952d5dd4de3728 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Tue, 24 Oct 2023 14:47:01 +0100 Subject: [PATCH] May have solved a bug made in the writing and speaking evaluation --- src/components/Solutions/Speaking.tsx | 53 +++++++++++++++++---------- src/pages/(exam)/ExamPage.tsx | 33 +++++++++-------- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/components/Solutions/Speaking.tsx b/src/components/Solutions/Speaking.tsx index 08c0c590..e0d0e955 100644 --- a/src/components/Solutions/Speaking.tsx +++ b/src/components/Solutions/Speaking.tsx @@ -9,10 +9,12 @@ import {speakingReverseMarking} from "@/utils/score"; const Waveform = dynamic(() => import("../Waveform"), {ssr: false}); -export default function Speaking({id, type, title, text, prompts, userSolutions, onNext, onBack}: SpeakingExercise & CommonProps) { +export default function Speaking({id, type, title, video_url, text, prompts, userSolutions, onNext, onBack}: SpeakingExercise & CommonProps) { const [solutionURL, setSolutionURL] = useState(); useEffect(() => { + console.log(userSolutions); + if (userSolutions && userSolutions.length > 0) { axios.post(`/api/speaking`, {path: userSolutions[0].solution}, {responseType: "arraybuffer"}).then(({data}) => { const blob = new Blob([data], {type: "audio/wav"}); @@ -26,27 +28,40 @@ export default function Speaking({id, type, title, text, prompts, userSolutions, return ( <>
-
+
{title} - - {text.split("\\n").map((line, index) => ( - - {line} -
-
- ))} -
+ {!video_url && ( + + {text.split("\\n").map((line, index) => ( + + {line} +
+
+ ))} +
+ )}
-
- You should talk about the following things: -
- {prompts.map((x, index) => ( -
  • - {x} -
  • - ))} -
    +
    + {video_url && ( +
    + +
    + )} + {prompts && prompts.length > 0 && ( +
    + You should talk about the following things: +
    + {prompts.map((x, index) => ( +
  • + {x} +
  • + ))} +
    +
    + )}
    diff --git a/src/pages/(exam)/ExamPage.tsx b/src/pages/(exam)/ExamPage.tsx index 83607752..e138667b 100644 --- a/src/pages/(exam)/ExamPage.tsx +++ b/src/pages/(exam)/ExamPage.tsx @@ -46,6 +46,9 @@ export default function ExamPage({page}: Props) { const router = useRouter(); useEffect(() => setSessionId(uuidv4()), []); + useEffect(() => { + console.log({userSolutions}); + }, [userSolutions]); useEffect(() => { selectedModules.length > 0 && timeSpent === 0 && !showSolutions; @@ -134,24 +137,22 @@ export default function ExamPage({page}: Props) { Promise.all( exam.exercises.map(async (exercise) => { - if (exercise.type === "writing") - return evaluateWritingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!).then((response) => { - if (response) { - setUserSolutions([...userSolutions.filter((x) => x.exercise !== exercise.id), response]); - } - }); + if (exercise.type === "writing") { + return await evaluateWritingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!); + } - if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking") - return evaluateSpeakingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!).then((response) => { - if (response) { - setUserSolutions([...userSolutions.filter((x) => x.exercise !== exercise.id), response]); - } - }); + if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking") { + return await evaluateSpeakingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!); + } }), - ).finally(() => { - setIsEvaluationLoading(false); - setHasBeenUploaded(false); - }); + ) + .then((responses) => { + setUserSolutions([...userSolutions, ...responses.filter((x) => !!x)] as any); + }) + .finally(() => { + setIsEvaluationLoading(false); + setHasBeenUploaded(false); + }); } axios.get("/api/stats/update");