diff --git a/enjoy/src/main/db/handlers/recordings-handler.ts b/enjoy/src/main/db/handlers/recordings-handler.ts index 9c0ee296..8291ce7f 100644 --- a/enjoy/src/main/db/handlers/recordings-handler.ts +++ b/enjoy/src/main/db/handlers/recordings-handler.ts @@ -67,6 +67,20 @@ class RecordingsHandler { }); } + private async sync(_event: IpcMainEvent, id: string) { + const recording = await Recording.findOne({ + where: { + id, + }, + }); + + if (!recording) { + throw new Error(t("models.recording.notFound")); + } + + return await recording.sync(); + } + private async syncAll(event: IpcMainEvent) { const recordings = await Recording.findAll({ where: { syncedAt: null }, @@ -150,7 +164,7 @@ class RecordingsHandler { }); } - private async upload(event: IpcMainEvent, id: string) { + private async upload(_event: IpcMainEvent, id: string) { const recording = await Recording.findOne({ where: { id, @@ -158,23 +172,10 @@ class RecordingsHandler { }); if (!recording) { - event.sender.send("on-notification", { - type: "error", - message: t("models.recording.notFound"), - }); + throw new Error(t("models.recording.notFound")); } - recording - .upload() - .then((res) => { - return res; - }) - .catch((err) => { - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }); + return await recording.upload(); } private async assess(event: IpcMainEvent, id: string) { @@ -361,6 +362,7 @@ class RecordingsHandler { register() { ipcMain.handle("recordings-find-all", this.findAll); ipcMain.handle("recordings-find-one", this.findOne); + ipcMain.handle("recordings-sync", this.sync); ipcMain.handle("recordings-sync-all", this.syncAll); ipcMain.handle("recordings-create", this.create); ipcMain.handle("recordings-destroy", this.destroy); diff --git a/enjoy/src/preload.ts b/enjoy/src/preload.ts index dd00f261..c4662c8f 100644 --- a/enjoy/src/preload.ts +++ b/enjoy/src/preload.ts @@ -257,6 +257,9 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", { findOne: (params: any) => { return ipcRenderer.invoke("recordings-find-one", params); }, + sync: (id: string) => { + return ipcRenderer.invoke("recordings-sync", id); + }, syncAll: () => { return ipcRenderer.invoke("recordings-sync-all"); }, diff --git a/enjoy/src/renderer/components/medias/media-current-recording.tsx b/enjoy/src/renderer/components/medias/media-current-recording.tsx index 68e82e52..250e905a 100644 --- a/enjoy/src/renderer/components/medias/media-current-recording.tsx +++ b/enjoy/src/renderer/components/medias/media-current-recording.tsx @@ -174,6 +174,14 @@ export const MediaCurrentRecording = () => { const handleShare = async () => { if (!currentRecording) return; + if (!currentRecording.isSynced) { + try { + await EnjoyApp.recordings.sync(currentRecording.id); + } catch (error) { + toast.error(t("shareFailed"), { description: error.message }); + return; + } + } if (!currentRecording.uploadedAt) { try { await EnjoyApp.recordings.upload(currentRecording.id); @@ -320,7 +328,7 @@ export const MediaCurrentRecording = () => { } const subscriptions = [ - regions.on("region-created", () => {}), + regions.on("region-created", () => { }), regions.on("region-clicked", (region, e) => { e.stopPropagation(); @@ -543,17 +551,16 @@ export const MediaCurrentRecording = () => { > = 80 - ? "text-green-500" - : currentRecording.pronunciationAssessment - .pronunciationScore >= 60 - ? "text-yellow-600" - : "text-red-500" - : "" - } + ${currentRecording.pronunciationAssessment + ? currentRecording.pronunciationAssessment + .pronunciationScore >= 80 + ? "text-green-500" + : currentRecording.pronunciationAssessment + .pronunciationScore >= 60 + ? "text-yellow-600" + : "text-red-500" + : "" + } `} /> {t("pronunciationAssessment")} diff --git a/enjoy/src/types/enjoy-app.d.ts b/enjoy/src/types/enjoy-app.d.ts index 91d27676..c28f2d5f 100644 --- a/enjoy/src/types/enjoy-app.d.ts +++ b/enjoy/src/types/enjoy-app.d.ts @@ -140,6 +140,7 @@ type EnjoyAppType = { recordings: { findAll: (where: any) => Promise; findOne: (where: any) => Promise; + sync: (id: string) => Promise; syncAll: () => Promise; create: (params: any) => Promise; update: (id: string, params: any) => Promise; diff --git a/enjoy/src/types/recording.d.ts b/enjoy/src/types/recording.d.ts index f9d72cef..3f52904d 100644 --- a/enjoy/src/types/recording.d.ts +++ b/enjoy/src/types/recording.d.ts @@ -10,6 +10,7 @@ type RecordingType = { duration?: number; src?: string; md5: string; + isSynced?: boolean; uploadedAt?: Date; createdAt: Date; updatedAt: Date;