Solved the bug where the user solutions were not loading

This commit is contained in:
Tiago Ribeiro
2023-08-31 12:19:09 +01:00
parent c2fb398707
commit 7dd96bf259

View File

@@ -13,12 +13,14 @@ export default function Speaking({id, type, title, text, prompts, userSolutions,
const [solutionURL, setSolutionURL] = useState<string>();
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 (