Sesame-iOS/Sesame/History/HistoryListItem.swift

64 lines
1.6 KiB
Swift
Raw Normal View History

import SwiftUI
2023-12-12 17:33:42 +01:00
import SwiftData
import SFSafeSymbols
2023-12-12 17:33:42 +01: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)
}
2023-08-14 10:39:29 +02:00
var roundTripText: String {
"\(Int(entry.roundTripTime * 1000)) ms"
}
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)"
}
var body: some View {
VStack(alignment: .leading) {
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)
.font(.headline)
Spacer()
Text(entryTime)
2023-12-12 17:33:42 +01: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-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.")
}
}