update error handling and add error boundary component

This commit is contained in:
2026-07-15 18:25:40 -07:00
parent f2ce3e82fa
commit bd9a6ccffe
15 changed files with 208 additions and 221 deletions
+1 -14
View File
@@ -1,6 +1,7 @@
import React, { useMemo } from 'react'
import { Box, Button, Chip, Divider, LinearProgress, Paper, Typography } from '@mui/material'
import type { DownloadOverlayItem } from '../components/DownloadsOverlay'
import { formatBytes } from '../utils/formatBytes'
type DownloadsPageProps = {
downloads: DownloadOverlayItem[]
@@ -10,20 +11,6 @@ type DownloadsPageProps = {
onClearFinished: () => void
}
function formatBytes(value?: number | null) {
if (!value || value <= 0) return null
const units = ['B', 'KB', 'MB', 'GB', 'TB']
let size = value
let unitIndex = 0
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024
unitIndex += 1
}
return `${size >= 10 || unitIndex === 0 ? size.toFixed(0) : size.toFixed(1)} ${units[unitIndex]}`
}
function getProgressPercent(download: DownloadOverlayItem) {
if (!download.totalBytes || download.totalBytes <= 0) return null
return Math.max(0, Math.min(100, (download.receivedBytes / download.totalBytes) * 100))