2022-05-01 18:30:30 +02:00
|
|
|
import SwiftUI
|
2023-04-11 18:18:31 +02:00
|
|
|
import SFSafeSymbols
|
2022-05-01 18:30:30 +02:00
|
|
|
|
|
|
|
private let df: DateFormatter = {
|
|
|
|
let df = DateFormatter()
|
|
|
|
df.dateStyle = .short
|
|
|
|
df.timeStyle = .short
|
|
|
|
return df
|
|
|
|
}()
|
|
|
|
|
|
|
|
struct HistoryListItem: View {
|
|
|
|
|
|
|
|
let entry: HistoryItem
|
|
|
|
|
|
|
|
var entryTime: String {
|
2023-04-11 18:18:31 +02:00
|
|
|
df.string(from: entry.requestDate)
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 18:18:31 +02:00
|
|
|
var roundTripText: String? {
|
2022-05-01 18:30:30 +02:00
|
|
|
guard let time = entry.roundTripTime else {
|
2023-04-11 18:18:31 +02:00
|
|
|
return nil
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
2023-04-11 18:18:31 +02:00
|
|
|
return "\(Int(time * 1000)) ms"
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var counterText: String {
|
2023-04-11 18:18:31 +02:00
|
|
|
let sentCounter = entry.request.id
|
|
|
|
let startText = "\(sentCounter)"
|
|
|
|
guard let rCounter = entry.responseMessage?.id else {
|
2022-05-01 18:30:30 +02:00
|
|
|
return startText
|
|
|
|
}
|
|
|
|
let diff = Int(rCounter) - Int(sentCounter)
|
2022-05-02 23:24:48 +02:00
|
|
|
guard diff != 1 && diff != 0 else {
|
2022-05-01 18:30:30 +02:00
|
|
|
return startText
|
|
|
|
}
|
2022-05-02 23:24:48 +02:00
|
|
|
return startText + " (\(diff))"
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 18:18:31 +02:00
|
|
|
var timeOffsetText: String? {
|
|
|
|
guard let offset = entry.clockOffset else {
|
|
|
|
return nil
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
2023-04-11 18:18:31 +02:00
|
|
|
return "\(offset) s"
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2023-04-11 18:18:31 +02:00
|
|
|
VStack(alignment: .leading) {
|
2022-05-01 18:30:30 +02:00
|
|
|
HStack {
|
|
|
|
Text(entry.response?.description ?? "")
|
|
|
|
.font(.headline)
|
|
|
|
Spacer()
|
|
|
|
Text(entryTime)
|
|
|
|
}.padding(.bottom, 1)
|
|
|
|
HStack {
|
2023-04-11 18:18:31 +02:00
|
|
|
if let roundTripText {
|
|
|
|
Image(systemSymbol: entry.usedLocalConnection ? .wifi : .network)
|
|
|
|
Text(roundTripText)
|
|
|
|
.font(.subheadline)
|
|
|
|
}
|
|
|
|
Image(systemSymbol: .personalhotspot)
|
2022-05-01 18:30:30 +02:00
|
|
|
Text(counterText)
|
|
|
|
.font(.subheadline)
|
2023-04-11 18:18:31 +02:00
|
|
|
if let timeOffsetText {
|
|
|
|
Image(systemSymbol: .stopwatch)
|
|
|
|
Text(timeOffsetText)
|
|
|
|
.font(.subheadline)
|
|
|
|
}
|
|
|
|
}.foregroundColor(.secondary)
|
|
|
|
}
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct HistoryListItem_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
HistoryListItem(entry: .mock)
|
|
|
|
}
|
|
|
|
}
|