blob: 2cb5d5d865fdd17eed1d5c4dd50a3a0cbf471969 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import type { StorageData } from "@/lib/storage"
interface StorageUsageProps {
data: StorageData
}
function formatFileSize(bytes: number): string {
if (bytes === 0) return "0 Bytes"
const k = 1024
const sizes = ["Bytes", "KB", "MB", "GB", "TB"]
const i = Math.floor(Math.log(bytes) / Math.log(k))
return Number.parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]
}
export function StorageUsage({ data }: StorageUsageProps) {
// Safety check for undefined data
if (!data) {
return (
<div className="bg-card rounded-lg border p-4">
<div className="flex items-center justify-between mb-2">
<span className="text-sm font-medium">Disk Usage</span>
<span className="text-sm text-muted-foreground">Loading...</span>
</div>
<div className="w-full h-2 bg-gray-200 rounded-full" />
</div>
)
}
const { totalDiskCapacity, totalDiskUsed } = data
// Calculate percentage of disk used
const diskUsedPercentage = totalDiskCapacity > 0 ? (totalDiskUsed / totalDiskCapacity) * 100 : 0
const availableSpace = totalDiskCapacity - totalDiskUsed
return (
<div className="bg-card rounded-lg border p-4">
<div className="flex items-center justify-between mb-2">
<span className="text-sm font-medium">Disk Usage</span>
<span className="text-sm text-muted-foreground">
{formatFileSize(totalDiskUsed)} used of {formatFileSize(totalDiskCapacity)}
</span>
</div>
{/* Simple progress bar showing disk usage */}
<div className="relative w-full h-2 bg-gray-200 rounded-full overflow-hidden">
<div
className="absolute top-0 left-0 h-full bg-blue-600 rounded-full transition-all duration-300"
style={{ width: `${Math.min(diskUsedPercentage, 100)}%` }}
/>
</div>
<div className="flex justify-between text-xs text-muted-foreground mt-2">
<div className="flex items-center gap-1">
<div className="w-2 h-2 bg-blue-600 rounded-full" />
<span>Used: {formatFileSize(totalDiskUsed)}</span>
</div>
<span>{formatFileSize(availableSpace)} available</span>
</div>
</div>
)
}
|