Sesame-iOS/Sesame/History/HistoryListItem.swift

70 lines
1.8 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
var clientNonceText: String {
"\(entry.message.clientChallenge)"
}
2023-12-12 17:33:42 +01:00
var serverNonceText: String {
"\(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)
Image(systemSymbol: .lockIphone)
Text(clientNonceText).padding(.trailing)
Image(systemSymbol: .doorRightHandClosed)
Text(serverNonceText).padding(.trailing)
}
.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.")
}
}