forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTorrentsTab.tsx
More file actions
375 lines (348 loc) · 13 KB
/
Copy pathTorrentsTab.tsx
File metadata and controls
375 lines (348 loc) · 13 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// src/components/dashboard/TorrentsTab.tsx
"use client"
import { H2 } from "@typography"
import clsx from "clsx"
import dynamic from "next/dynamic"
import { useState } from "react"
import { ParallelTorrentsChart } from "@/components/charts/ParallelTorrentsChart"
import { StorageSunburst } from "@/components/charts/StorageSunburst"
import {
numbersNeedsWideCard,
TagGroupBreakdownChart,
} from "@/components/charts/TagGroupBreakdownChart"
import { TorrentActivityHeatmap } from "@/components/charts/TorrentActivityHeatmap"
import { TorrentAgeTimeline } from "@/components/charts/TorrentAgeTimeline"
import { TorrentAvgSeedTime } from "@/components/charts/TorrentAvgSeedTime"
import { TorrentCategoryAcquisition } from "@/components/charts/TorrentCategoryAcquisition"
import { TorrentCrossSeedDonut } from "@/components/charts/TorrentCrossSeedDonut"
import { TorrentRatioDistribution } from "@/components/charts/TorrentRatioDistribution"
import { TorrentSeedTimeDistribution } from "@/components/charts/TorrentSeedTimeDistribution"
import { TorrentSizeBreakdown } from "@/components/charts/TorrentSizeBreakdown"
import {
ActiveTransfersTable,
CategoryCard,
NoDownloadClientState,
NoTagState,
TorrentRankingTable,
TorrentStatCards,
UnsatisfiedTorrentsTable,
} from "@/components/dashboard/torrents"
import { Card, LazySection, Notice, TorrentTabSkeleton } from "@/components/ui"
import type { TrackerTorrentsData } from "@/hooks/useTrackerTorrents"
import { formatSpeed, formatTimeAgo } from "@/lib/formatters"
const TorrentAgeScatter3D = dynamic(
() => import("@/components/charts/TorrentAgeScatter3D").then((m) => m.TorrentAgeScatter3D),
{ ssr: false }
)
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
interface TorrentsTabProps {
trackerName?: string
qbtTag: string | null
accentColor: string
data: TrackerTorrentsData
trackerSeedingCount?: number | null
}
// ---------------------------------------------------------------------------
// Component
// ---------------------------------------------------------------------------
function TorrentsTab({
trackerName,
qbtTag,
accentColor,
data,
trackerSeedingCount,
}: TorrentsTabProps) {
const [staleDismissed, setStaleDismissed] = useState(false)
if (data.loading) {
return <TorrentTabSkeleton />
}
if (!qbtTag) return <NoTagState trackerName={trackerName ?? "this tracker"} />
if (data.noClients) return <NoDownloadClientState />
return (
<div className="flex flex-col gap-8">
{/* Error banner */}
{data.torrentError && <Notice variant="warn" box message={data.torrentError} />}
{/* Stale data banner that's dismissible, reappears on next mount */}
{data.stale && data.cachedAt && !staleDismissed && (
<div className="px-4 py-3 text-xs font-mono text-secondary nm-inset-sm rounded-nm-md flex items-center gap-2">
<span className="text-warn">●</span>
<span className="flex-1">
Showing cached data from {formatTimeAgo(data.cachedAt)} — client offline
</span>
<button
type="button"
onClick={() => setStaleDismissed(true)}
className="text-muted hover:text-secondary transition-colors text-sm leading-none"
aria-label="Dismiss stale data banner"
>
✕
</button>
</div>
)}
{/* Active Transfers */}
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<div className="flex flex-col gap-3 min-w-0 [&>*:last-child]:flex-1">
<H2 className="uppercase tracking-wider flex items-center gap-2">
{data.activelyDownloading.length > 0 && (
<span className="inline-block w-2 h-2 rounded-full bg-warn animate-pulse" />
)}
Active Downloads ({data.activelyDownloading.length})
{data.activelyDownloading.length > 0 && (
<span className="font-mono text-warn ml-auto mr-2 text-2xs normal-case tracking-normal">
{formatSpeed(data.activelyDownloading.reduce((s, t) => s + t.downloadSpeed, 0))}
</span>
)}
</H2>
<ActiveTransfersTable
torrents={data.activelyDownloading}
mode="downloading"
accentColor={accentColor}
showClientName={data.clientCount > 1}
/>
</div>
<div className="flex flex-col gap-3 min-w-0 [&>*:last-child]:flex-1">
<H2 className="uppercase tracking-wider flex items-center gap-2">
{data.activelySeedingTorrents.length > 0 && (
<span
className="inline-block w-2 h-2 rounded-full animate-pulse"
style={{ backgroundColor: accentColor }}
/>
)}
Active Uploads ({data.activelySeedingTorrents.length})
{data.activelySeedingTorrents.length > 0 && (
<span className="font-mono text-accent ml-auto mr-2 text-2xs normal-case tracking-normal">
{formatSpeed(data.activelySeedingTorrents.reduce((s, t) => s + t.uploadSpeed, 0))}
</span>
)}
</H2>
<ActiveTransfersTable
torrents={data.activelySeedingTorrents}
mode="uploading"
accentColor={accentColor}
showClientName={data.clientCount > 1}
/>
</div>
</div>
{/* Stat Cards */}
<TorrentStatCards
torrents={data.torrents}
seedingTorrents={data.seedingTorrents}
totalSize={data.totalSize}
crossSeededCount={data.crossSeeded.length}
deadCount={data.deadCount}
trackerSeedingCount={trackerSeedingCount ?? null}
unsatisfiedCount={data.unsatisfiedCount}
hnrRiskCount={data.hnrRiskCount}
accentColor={accentColor}
clientCount={data.clientCount}
/>
{/* Category + Cross-Seed */}
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<CategoryCard categories={data.categoryStats} accentColor={accentColor} />
<Card
lazy
trackerColor={accentColor}
className="flex flex-col gap-4"
title="Cross-Seed Ratio"
>
{data.crossSeedTags.length === 0 ? (
<div className="flex items-center justify-center flex-1">
<p className="text-xs font-mono text-tertiary text-center">
No cross-seed tags configured.
<br />
Set them in Settings → Download Clients.
</p>
</div>
) : (
<TorrentCrossSeedDonut
crossSeeded={data.crossSeeded.length}
unique={data.torrents.length - data.crossSeeded.length}
accentColor={accentColor}
/>
)}
</Card>
</div>
{/* Tag Group Breakdowns */}
{data.tagGroupBreakdowns.length > 0 && (
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
{data.tagGroupBreakdowns.map(({ group, memberCounts, unmatchedCount }) => {
const effectiveCount =
memberCounts.length + (group.countUnmatched && unmatchedCount != null ? 1 : 0)
const isSingleNumber = group.chartType === "numbers" && effectiveCount === 1
const wideCard =
group.chartType === "numbers" &&
numbersNeedsWideCard(memberCounts.length, group.countUnmatched, unmatchedCount)
return (
<Card
key={group.id}
trackerColor={accentColor}
className={clsx(
"flex flex-col gap-4",
wideCard && "lg:col-span-2",
isSingleNumber && "min-h-48"
)}
>
<H2 className="card-heading">
{group.emoji ? `${group.emoji} ` : ""}
{group.name}
</H2>
<TagGroupBreakdownChart
groupName={group.name}
members={memberCounts}
accentColor={accentColor}
chartType={group.chartType}
countUnmatched={group.countUnmatched}
unmatchedCount={unmatchedCount}
/>
</Card>
)
})}
</div>
)}
{/* qbitmanage Breakdown */}
{data.qbitmanageBreakdown.length > 0 && (
<Card trackerColor={accentColor} className="flex flex-col gap-4" title="qbitmanage Status">
<TagGroupBreakdownChart
groupName="qbitmanage Status"
members={data.qbitmanageBreakdown}
accentColor={accentColor}
/>
</Card>
)}
{/* Ratio + Seed Time Distribution */}
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<Card
lazy
trackerColor={accentColor}
className="flex flex-col gap-4"
title="Ratio Distribution"
>
<TorrentRatioDistribution torrents={data.torrents} accentColor={accentColor} />
</Card>
<Card
lazy
trackerColor={accentColor}
className="flex flex-col gap-4"
title="Seed Time Distribution"
>
<TorrentSeedTimeDistribution
torrents={data.torrents}
seedTimeHours={
data.requiredSeedSeconds != null ? data.requiredSeedSeconds / 3600 : null
}
accentColor={accentColor}
height={280}
/>
</Card>
</div>
{/* Size Breakdown + Activity Heatmap */}
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<Card
lazy
trackerColor={accentColor}
className="flex flex-col gap-4"
title="Size by Category"
>
<TorrentSizeBreakdown categories={data.categoryStats} accentColor={accentColor} />
</Card>
<Card
lazy
trackerColor={accentColor}
className="flex flex-col gap-4"
title="Torrent Add Heatmap"
>
<TorrentActivityHeatmap torrents={data.torrents} accentColor={accentColor} height={320} />
</Card>
</div>
{/* Library Growth */}
<Card lazy trackerColor={accentColor} className="flex flex-col gap-4" title="Library Growth">
<TorrentAgeTimeline torrents={data.torrents} accentColor={accentColor} />
</Card>
{/* Category Acquisition */}
<Card
lazy
title="Torrents Added by Category"
subtitle="Monthly grabs by category"
trackerColor={accentColor}
className="flex flex-col gap-4"
>
<TorrentCategoryAcquisition torrents={data.torrents} accentColor={accentColor} />
</Card>
{/* Avg Seed Time by Cohort */}
<Card
lazy
title="Average Seed Time by Cohort"
trackerColor={accentColor}
className="flex flex-col gap-4"
>
<TorrentAvgSeedTime torrents={data.torrents} accentColor={accentColor} />
</Card>
{/* 3D Scatter */}
<LazySection minHeight={400}>
<Card
title="Torrent Library — 3D Scatter"
trackerColor={accentColor}
className="flex flex-col gap-4"
>
<TorrentAgeScatter3D torrents={data.torrents} accentColor={accentColor} />
</Card>
</LazySection>
{/* Unsatisfied Torrents */}
{data.requiredSeedSeconds && (
<div className="flex flex-col gap-3">
<H2 className="uppercase tracking-wider">
Unsatisfied Torrents ({data.unsatisfiedSorted.length})
</H2>
<UnsatisfiedTorrentsTable
torrents={data.unsatisfiedSorted}
requiredSeconds={data.requiredSeedSeconds}
accentColor={accentColor}
/>
</div>
)}
{/* Top Seeded */}
<div className="flex flex-col gap-3">
<H2 className="uppercase tracking-wider">Top Seeded Torrents</H2>
<TorrentRankingTable
variant="top-seeded"
torrents={data.topBySeeding}
trackerColor={accentColor}
/>
</div>
{/* Parallel Coordinates */}
<Card lazy trackerColor={accentColor} className="flex flex-col gap-4" title="Torrent Profile">
<ParallelTorrentsChart torrents={data.torrents} trackerColor={accentColor} height={380} />
</Card>
{/* Storage Sunburst */}
<Card
lazy
trackerColor={accentColor}
className="flex flex-col gap-4"
title="Storage Breakdown"
>
<StorageSunburst
torrents={data.torrents.map((t) => ({
name: t.name,
size: t.size,
category: t.category,
}))}
accentColor={accentColor}
height={480}
/>
</Card>
{/* Elder Torrents */}
<div className="flex flex-col gap-3">
<H2 className="uppercase tracking-wider">Elder Torrents</H2>
<TorrentRankingTable
variant="elder"
torrents={data.elderTorrents}
trackerColor={accentColor}
/>
</div>
</div>
)
}
export type { TorrentsTabProps }
export { TorrentsTab }