diff --git a/enjoy/src/renderer/components/pronunciation-assessments/pronunciation-assessment-form.tsx b/enjoy/src/renderer/components/pronunciation-assessments/pronunciation-assessment-form.tsx index 58b9efbc..9de7f777 100644 --- a/enjoy/src/renderer/components/pronunciation-assessments/pronunciation-assessment-form.tsx +++ b/enjoy/src/renderer/components/pronunciation-assessments/pronunciation-assessment-form.tsx @@ -64,32 +64,34 @@ export const PronunciationAssessmentForm = () => { } const { language, referenceText } = data; + let recording: RecordingType; try { - setSubmitting(true); - const recording = await createRecording(data); - toast.promise( - createAssessment({ - language, - reference: referenceText, - recording, - }) - .then(() => { - navigate("/pronunciation_assessments"); - }) - .catch(() => { - EnjoyApp.recordings.destroy(recording.id); - }) - .finally(() => setSubmitting(false)), - { - loading: t("assessing"), - success: t("assessedSuccessfully"), - error: (err) => err.message, - } - ); + recording = await createRecording(data); } catch (err) { toast.error(err.message); - setSubmitting(false); } + if (!recording) return; + + setSubmitting(true); + toast.promise( + createAssessment({ + language, + reference: referenceText, + recording, + }) + .then(() => { + navigate("/pronunciation_assessments"); + }) + .catch(() => { + EnjoyApp.recordings.destroy(recording.id); + }) + .finally(() => setSubmitting(false)), + { + loading: t("assessing"), + success: t("assessedSuccessfully"), + error: (err) => err.message, + } + ); }; const createRecording = async ( diff --git a/enjoy/src/renderer/hooks/use-pronunciation-assessments.tsx b/enjoy/src/renderer/hooks/use-pronunciation-assessments.tsx index 03171e78..bd343101 100644 --- a/enjoy/src/renderer/hooks/use-pronunciation-assessments.tsx +++ b/enjoy/src/renderer/hooks/use-pronunciation-assessments.tsx @@ -2,6 +2,7 @@ import * as sdk from "microsoft-cognitiveservices-speech-sdk"; import { useContext } from "react"; import { AppSettingsProviderContext } from "@renderer/context"; import camelcaseKeys from "camelcase-keys"; +import { toast } from "@renderer/components/ui"; export const usePronunciationAssessments = () => { const { webApi, EnjoyApp } = useContext(AppSettingsProviderContext); @@ -18,7 +19,7 @@ export const usePronunciationAssessments = () => { recording = await EnjoyApp.recordings.findOne(targetId); } - await EnjoyApp.recordings.sync(recording.id); + EnjoyApp.recordings.sync(recording.id).catch((err) => toast.error(err)); const blob = await (await fetch(recording.src)).blob(); targetId = recording.id; targetType = "Recording";