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