2022-05-01 18:30:30 +02:00
|
|
|
import SwiftUI
|
2023-12-12 17:33:42 +01:00
|
|
|
import SwiftData
|
2023-04-11 18:18:31 +02:00
|
|
|
import SFSafeSymbols
|
2022-05-01 18:30:30 +02:00
|
|
|
|
2023-12-12 17:33:42 +01:00
|
|
|
|
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-12-12 17:33:42 +01:00
|
|
|
df.string(from: entry.startDate)
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
|
2023-08-14 10:39:29 +02:00
|
|
|
var roundTripText: String {
|
|
|
|
"\(Int(entry.roundTripTime * 1000)) ms"
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
|
2024-01-14 12:48:43 +01:00
|
|
|
var noncesText: String {
|
|
|
|
"\(entry.message.clientChallenge) → \(entry.message.serverChallenge)"
|
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 {
|
2023-12-12 17:33:42 +01:00
|
|
|
Image(systemSymbol: entry.route.symbol)
|
2023-08-14 10:39:29 +02:00
|
|
|
Text(entry.response.description)
|
2022-05-01 18:30:30 +02:00
|
|
|
.font(.headline)
|
|
|
|
Spacer()
|
|
|
|
Text(entryTime)
|
2023-12-12 17:33:42 +01:00
|
|
|
}
|
2022-05-01 18:30:30 +02:00
|
|
|
HStack {
|
2023-12-12 17:33:42 +01:00
|
|
|
Image(systemSymbol: .arrowUpArrowDownCircle)
|
|
|
|
Text(roundTripText).padding(.trailing)
|
2024-01-14 12:48:43 +01:00
|
|
|
Image(systemSymbol: .keyHorizontal)
|
|
|
|
Text(noncesText)
|
2023-12-12 17:33:42 +01:00
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.font(.footnote)
|
2023-04-11 18:18:31 +02:00
|
|
|
}
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-12 17:33:42 +01:00
|
|
|
#Preview {
|
|
|
|
do {
|
|
|
|
let config = ModelConfiguration(isStoredInMemoryOnly: true)
|
|
|
|
let container = try ModelContainer(for: HistoryItem.self, configurations: config)
|
|
|
|
|
|
|
|
let item = HistoryItem.mock
|
|
|
|
container.mainContext.insert(item)
|
|
|
|
try container.mainContext.save()
|
|
|
|
return HistoryListItem(entry: item)
|
|
|
|
.modelContainer(container)
|
|
|
|
} catch {
|
|
|
|
fatalError("Failed to create model container.")
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
|
|
|
}
|