51 lines
1.7 KiB
Swift
51 lines
1.7 KiB
Swift
import SwiftUI
|
|
import ProxyCore
|
|
|
|
struct TrafficRowView: View {
|
|
let traffic: CapturedTraffic
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
HStack(spacing: 6) {
|
|
MethodBadge(method: traffic.method)
|
|
StatusBadge(statusCode: traffic.statusCode)
|
|
|
|
Spacer()
|
|
|
|
Text(traffic.startDate, format: .dateTime.hour().minute().second().secondFraction(.fractional(3)))
|
|
.font(.caption2)
|
|
.foregroundStyle(.secondary)
|
|
|
|
Text(traffic.formattedDuration)
|
|
.font(.caption2)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
Text(traffic.url)
|
|
.font(.caption)
|
|
.lineLimit(3)
|
|
.foregroundStyle(.primary)
|
|
|
|
HStack(spacing: 12) {
|
|
if traffic.requestBodySize > 0 {
|
|
Label(formatBytes(traffic.requestBodySize), systemImage: "arrow.up.circle.fill")
|
|
.font(.caption2)
|
|
.foregroundStyle(.green)
|
|
}
|
|
if traffic.responseBodySize > 0 {
|
|
Label(formatBytes(traffic.responseBodySize), systemImage: "arrow.down.circle.fill")
|
|
.font(.caption2)
|
|
.foregroundStyle(.blue)
|
|
}
|
|
}
|
|
}
|
|
.padding(.vertical, 4)
|
|
}
|
|
|
|
private func formatBytes(_ bytes: Int) -> String {
|
|
if bytes < 1024 { return "\(bytes) B" }
|
|
if bytes < 1_048_576 { return String(format: "%.1f KB", Double(bytes) / 1024) }
|
|
return String(format: "%.1f MB", Double(bytes) / 1_048_576)
|
|
}
|
|
}
|