diff --git a/enjoy/src/main/db/handlers/recordings-handler.ts b/enjoy/src/main/db/handlers/recordings-handler.ts index 6949bb4a..1fd1a5df 100644 --- a/enjoy/src/main/db/handlers/recordings-handler.ts +++ b/enjoy/src/main/db/handlers/recordings-handler.ts @@ -15,6 +15,7 @@ import { import dayjs from "dayjs"; import { t } from "i18next"; import log from "@main/logger"; +import { NIL as NIL_UUID } from "uuid"; const logger = log.scope("db/handlers/recordings-handler"); @@ -120,8 +121,13 @@ class RecordingsHandler { }; } ) { - const { targetId, targetType, referenceId, referenceText, duration } = - options; + const { + targetId = NIL_UUID, + targetType = "None", + referenceId, + referenceText, + duration, + } = options; const recording = await Recording.createFromBlob(options.blob, { targetId, targetType, 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 bbd93bfc..58b9efbc 100644 --- a/enjoy/src/renderer/components/pronunciation-assessments/pronunciation-assessment-form.tsx +++ b/enjoy/src/renderer/components/pronunciation-assessments/pronunciation-assessment-form.tsx @@ -64,28 +64,32 @@ export const PronunciationAssessmentForm = () => { } const { language, referenceText } = data; - const recording = await createRecording(data); - - setSubmitting(true); - toast.promise( - createAssessment({ - language, - reference: referenceText, - recording, - }) - .then(() => { - navigate("/pronunciation_assessments"); + try { + setSubmitting(true); + const recording = await createRecording(data); + toast.promise( + createAssessment({ + language, + reference: referenceText, + recording, }) - .catch(() => { - EnjoyApp.recordings.destroy(recording.id); - }) - .finally(() => setSubmitting(false)), - { - loading: t("assessing"), - success: t("assessedSuccessfully"), - error: (err) => err.message, - } - ); + .then(() => { + navigate("/pronunciation_assessments"); + }) + .catch(() => { + EnjoyApp.recordings.destroy(recording.id); + }) + .finally(() => setSubmitting(false)), + { + loading: t("assessing"), + success: t("assessedSuccessfully"), + error: (err) => err.message, + } + ); + } catch (err) { + toast.error(err.message); + setSubmitting(false); + } }; const createRecording = async ( @@ -98,7 +102,8 @@ export const PronunciationAssessmentForm = () => { } else { arrayBuffer = await new Blob([file[0]]).arrayBuffer(); } - return await EnjoyApp.recordings.create({ + + return EnjoyApp.recordings.create({ language, referenceText, blob: {