import SwiftUI struct HistoryView: View { @ObservedObject var history: HistoryManager private var unlockCount: Int { history.entries.count { $0.response == .openSesame } } private var percentage: Double { guard history.entries.count > 0 else { return 0 } return Double(unlockCount * 100) / Double(history.entries.count) } var body: some View { NavigationView { List { HStack { VStack(alignment: .leading) { Text("\(history.entries.count) requests") .foregroundColor(.primary) .font(.body) Text(String(format: "%.1f %% success", percentage)) .foregroundColor(.secondary) .font(.footnote) } Spacer() } .listRowBackground(Color.clear) ForEach(history.entries) { item in NavigationLink { HistoryItemDetail(item: item, history: history) } label: { HistoryListRow(item: item) } .swipeActions(edge: .trailing) { Button { delete(item: item) } label: { Label("Delete", systemSymbol: .trash) }.tint(.red) } } } .navigationTitle("History") } } private func delete(item: HistoryItem) { guard history.delete(item: item) else { return } } } struct HistoryView_Previews: PreviewProvider { static var previews: some View { HistoryView(history: HistoryManager()) } }