mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat(downloads): let the download progress toast be minimized
The download progress toast sits in the bottom-right corner on top of the comment composer, blocking the voice-recording button and the comment box for the whole duration of a download. Render it through toast.custom so it can be collapsed to a small pill (percent + spinner) and expanded again while the download keeps running. The minimized choice sticks for the rest of the session. The sonner <li> is click-through, so only the panel itself covers the controls underneath. Also dismiss the panel on failure — it had duration: Infinity and used to stay on screen forever after an error.
This commit is contained in:
@@ -40,10 +40,17 @@ export function formatBytes(bytes: number): string {
|
||||
return `${(mb / 1024).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
/** Percentage done, or null when the server didn't send a Content-Length. */
|
||||
export function downloadProgressPercent(progress: DownloadProgress): number | null {
|
||||
const { receivedBytes, totalBytes } = progress;
|
||||
if (!totalBytes || totalBytes <= 0) return null;
|
||||
return Math.min(100, Math.floor((receivedBytes / totalBytes) * 100));
|
||||
}
|
||||
|
||||
export function downloadProgressLabel(progress: DownloadProgress): string {
|
||||
const { receivedBytes, totalBytes } = progress;
|
||||
if (totalBytes && totalBytes > 0) {
|
||||
const pct = Math.min(100, Math.floor((receivedBytes / totalBytes) * 100));
|
||||
const pct = downloadProgressPercent(progress);
|
||||
if (pct !== null && totalBytes) {
|
||||
return `${pct}% · ${formatBytes(receivedBytes)} / ${formatBytes(totalBytes)}`;
|
||||
}
|
||||
return formatBytes(receivedBytes);
|
||||
|
||||
Reference in New Issue
Block a user