From 7dd96bf259af601a52bb5b52aa68df4c885103ae Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Thu, 31 Aug 2023 12:19:09 +0100 Subject: [PATCH] Solved the bug where the user solutions were not loading --- src/components/Solutions/Speaking.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Solutions/Speaking.tsx b/src/components/Solutions/Speaking.tsx index 663bf13e..08c0c590 100644 --- a/src/components/Solutions/Speaking.tsx +++ b/src/components/Solutions/Speaking.tsx @@ -13,12 +13,14 @@ export default function Speaking({id, type, title, text, prompts, userSolutions, const [solutionURL, setSolutionURL] = useState(); useEffect(() => { - axios.post(`/api/speaking`, {path: userSolutions[0].solution}, {responseType: "arraybuffer"}).then(({data}) => { - const blob = new Blob([data], {type: "audio/wav"}); - const url = URL.createObjectURL(blob); + 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"}); + const url = URL.createObjectURL(blob); - setSolutionURL(url); - }); + setSolutionURL(url); + }); + } }, [userSolutions]); return (