Skip to content

Commit c8d2e6b

Browse files
committed
Notify recovered recordings with actionable toasts
1 parent 78a014f commit c8d2e6b

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ const createRecordingDownloadName = (
112112
return `cap-recording-${timestamp}.${extension}`;
113113
};
114114

115+
const triggerBrowserDownload = (url: string, fileName: string) => {
116+
const anchor = document.createElement("a");
117+
anchor.href = url;
118+
anchor.download = fileName;
119+
document.body.appendChild(anchor);
120+
anchor.click();
121+
document.body.removeChild(anchor);
122+
};
123+
124+
const recoveredToastId = (id: string) => `recovered-${id}`;
125+
115126
export const useWebRecorder = ({
116127
organisationId,
117128
selectedMicId,
@@ -285,6 +296,7 @@ export const useWebRecorder = ({
285296
}, []);
286297

287298
const dismissRecoveredDownload = useCallback((id: string) => {
299+
toast.dismiss(recoveredToastId(id));
288300
const url = recoveredDownloadUrlsRef.current.get(id);
289301
if (url) {
290302
URL.revokeObjectURL(url);
@@ -344,11 +356,26 @@ export const useWebRecorder = ({
344356
});
345357

346358
setRecoveredDownloads(nextDownloads);
347-
toast.info(
348-
nextDownloads.length === 1
349-
? "Recovered an unfinished local recording."
350-
: `Recovered ${nextDownloads.length} unfinished local recordings.`,
351-
);
359+
for (const download of nextDownloads) {
360+
toast.info("Recovered an unfinished recording", {
361+
id: recoveredToastId(download.id),
362+
duration: Infinity,
363+
description: new Date(download.createdAt).toLocaleString(),
364+
action: {
365+
label: "Download",
366+
onClick: () => {
367+
triggerBrowserDownload(download.url, download.fileName);
368+
setTimeout(() => dismissRecoveredDownload(download.id), 500);
369+
},
370+
},
371+
cancel: {
372+
label: "Dismiss",
373+
onClick: () => {
374+
dismissRecoveredDownload(download.id);
375+
},
376+
},
377+
});
378+
}
352379
})
353380
.catch((error) => {
354381
console.error("Failed to recover orphaned recording spools", error);
@@ -357,7 +384,7 @@ export const useWebRecorder = ({
357384
return () => {
358385
cancelled = true;
359386
};
360-
}, []);
387+
}, [dismissRecoveredDownload]);
361388

362389
const disposeRecordingSpool = useCallback(async () => {
363390
const spool = recordingSpoolRef.current;

apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/web-recorder-dialog.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ export const WebRecorderDialog = () => {
385385
href={download.url}
386386
download={download.fileName}
387387
className="font-medium text-blue-11 hover:text-blue-12"
388+
onClick={() =>
389+
setTimeout(
390+
() => dismissRecoveredDownload(download.id),
391+
500,
392+
)
393+
}
388394
>
389395
Download
390396
</a>

0 commit comments

Comments
 (0)