forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcosystemStatsSection.tsx
More file actions
96 lines (90 loc) · 3 KB
/
Copy pathEcosystemStatsSection.tsx
File metadata and controls
96 lines (90 loc) · 3 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// src/components/dashboard/EcosystemStatsSection.tsx
"use client"
import { H2 } from "@typography"
import type { ReactNode } from "react"
import {
DownloadArrowIcon,
GridIcon,
LeechingIcon,
RatioIcon,
SeedingIcon,
ShieldIcon,
UploadArrowIcon,
} from "@/components/ui/Icons"
import { StatCard } from "@/components/ui/StatCard"
import type { AggregateStats } from "@/lib/dashboard"
import { formatBytesFromString, formatCount, formatRatio, splitValueUnit } from "@/lib/formatters"
import type { TrackerSummary } from "@/types/api"
const AGGREGATE_ICONS: Record<string, ReactNode> = {
trackers: <GridIcon width="16" height="16" />,
uploaded: <UploadArrowIcon width="16" height="16" />,
downloaded: <DownloadArrowIcon width="16" height="16" />,
buffer: <ShieldIcon width="16" height="16" />,
ratio: <RatioIcon width="16" height="16" />,
seeding: <SeedingIcon width="16" height="16" />,
leeching: <LeechingIcon width="16" height="16" />,
}
interface EcosystemStatsSectionProps {
trackers: TrackerSummary[]
aggregateStats: AggregateStats
}
function EcosystemStatsSection({ trackers, aggregateStats }: EcosystemStatsSectionProps) {
const uploadedParts = splitValueUnit(formatBytesFromString(aggregateStats.totalUploaded))
const downloadedParts = splitValueUnit(formatBytesFromString(aggregateStats.totalDownloaded))
const bufferParts = splitValueUnit(formatBytesFromString(aggregateStats.totalBuffer))
return (
<div className="flex flex-col gap-4">
<H2>Ecosystem</H2>
<div className="grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-4">
<StatCard
label="Trackers"
value={trackers.length.toString()}
icon={AGGREGATE_ICONS.trackers}
/>
<StatCard
label="Total Uploaded"
value={uploadedParts.num}
unit={uploadedParts.unit}
icon={AGGREGATE_ICONS.uploaded}
/>
<StatCard
label="Total Downloaded"
value={downloadedParts.num}
unit={downloadedParts.unit}
icon={AGGREGATE_ICONS.downloaded}
/>
<StatCard
label="Total Buffer"
value={bufferParts.num}
unit={bufferParts.unit}
icon={AGGREGATE_ICONS.buffer}
/>
<StatCard
label="Avg Ratio"
value={formatRatio(aggregateStats.avgRatio)}
icon={AGGREGATE_ICONS.ratio}
trend={
aggregateStats.avgRatio === null
? undefined
: aggregateStats.avgRatio >= 2
? "up"
: aggregateStats.avgRatio >= 1
? "flat"
: "down"
}
/>
<StatCard
label="Seeding"
value={formatCount(aggregateStats.totalSeeding)}
icon={AGGREGATE_ICONS.seeding}
/>
<StatCard
label="Leeching"
value={formatCount(aggregateStats.totalLeeching)}
icon={AGGREGATE_ICONS.leeching}
/>
</div>
</div>
)
}
export { EcosystemStatsSection }