Solved another weird bug

This commit is contained in:
Tiago Ribeiro
2024-01-26 11:49:03 +00:00
parent 3eafc799ab
commit 4e199931aa
2 changed files with 12 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ export default function InteractiveSpeaking({
const [diffNumber, setDiffNumber] = useState<0 | 1 | 2 | 3>(0); const [diffNumber, setDiffNumber] = useState<0 | 1 | 2 | 3>(0);
useEffect(() => { useEffect(() => {
if (userSolutions && userSolutions.length > 0) { if (userSolutions && userSolutions.length > 0 && userSolutions[0].solution) {
Promise.all(userSolutions[0].solution.map((x) => axios.post(`/api/speaking`, {path: x.answer}, {responseType: "arraybuffer"}))).then( Promise.all(userSolutions[0].solution.map((x) => axios.post(`/api/speaking`, {path: x.answer}, {responseType: "arraybuffer"}))).then(
(values) => { (values) => {
setSolutionsURL( setSolutionsURL(
@@ -239,7 +239,11 @@ export default function InteractiveSpeaking({
onNext({ onNext({
exercise: id, exercise: id,
solutions: userSolutions, solutions: userSolutions,
score: {total: 100, missing: 0, correct: speakingReverseMarking[userSolutions[0]!.evaluation!.overall] || 0}, score: {
total: 100,
missing: 0,
correct: userSolutions[0]?.evaluation ? speakingReverseMarking[userSolutions[0]!.evaluation!.overall] || 0 : 0,
},
type, type,
}) })
} }

View File

@@ -19,7 +19,7 @@ export default function Speaking({id, type, title, video_url, text, prompts, use
const [showDiff, setShowDiff] = useState(false); const [showDiff, setShowDiff] = useState(false);
useEffect(() => { useEffect(() => {
if (userSolutions && userSolutions.length > 0) { if (userSolutions && userSolutions.length > 0 && userSolutions[0].solution) {
axios.post(`/api/speaking`, {path: userSolutions[0].solution}, {responseType: "arraybuffer"}).then(({data}) => { axios.post(`/api/speaking`, {path: userSolutions[0].solution}, {responseType: "arraybuffer"}).then(({data}) => {
const blob = new Blob([data], {type: "audio/wav"}); const blob = new Blob([data], {type: "audio/wav"});
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
@@ -29,10 +29,6 @@ export default function Speaking({id, type, title, video_url, text, prompts, use
} }
}, [userSolutions]); }, [userSolutions]);
useEffect(() => {
console.log(userSolutions);
}, [userSolutions]);
return ( return (
<> <>
<Modal title="Correction" isOpen={showDiff} onClose={() => setShowDiff(false)}> <Modal title="Correction" isOpen={showDiff} onClose={() => setShowDiff(false)}>
@@ -205,7 +201,11 @@ export default function Speaking({id, type, title, video_url, text, prompts, use
onNext({ onNext({
exercise: id, exercise: id,
solutions: userSolutions, solutions: userSolutions,
score: {total: 100, missing: 0, correct: speakingReverseMarking[userSolutions[0]!.evaluation!.overall] || 0}, score: {
total: 100,
missing: 0,
correct: userSolutions[0]?.evaluation ? speakingReverseMarking[userSolutions[0]!.evaluation!.overall] || 0 : 0,
},
type, type,
}) })
} }