Refactor Dashboard traffic cards with line charts

This commit is contained in:
世界
2025-12-06 21:19:37 +08:00
parent 52efbd97d2
commit 0e206cc452
17 changed files with 299 additions and 93 deletions
@@ -0,0 +1,45 @@
import Libbox
import Library
import SwiftUI
public struct DownloadTrafficCard: View {
@EnvironmentObject private var commandClient: CommandClient
public init() {}
public var body: some View {
DashboardCardView(title: "", isHalfWidth: true) {
VStack(alignment: .leading, spacing: 8) {
DashboardCardHeader(icon: "arrow.down.circle.fill", title: "Download")
if ApplicationLibrary.inPreview {
Text("249 MB/s")
.font(.title2)
.fontWeight(.medium)
Text("5.6 GB")
.font(.subheadline)
.foregroundStyle(.secondary)
} else if let message = commandClient.status, message.trafficAvailable {
Text("\(LibboxFormatBytes(message.downlink))/s")
.font(.title2)
.fontWeight(.medium)
Text(LibboxFormatBytes(message.downlinkTotal))
.font(.subheadline)
.foregroundStyle(.secondary)
} else {
Text("...")
.font(.title2)
.fontWeight(.medium)
Text("...")
.font(.subheadline)
.foregroundStyle(.secondary)
}
TrafficLineChart(
data: commandClient.downlinkHistory,
lineColor: .primary
)
}
}
}
}