TempTrack-iOS/TempTrack/Views/HistoryList.swift

42 lines
1.3 KiB
Swift
Raw Permalink Normal View History

import SwiftUI
struct HistoryList: View {
@EnvironmentObject
var storage: PersistentStorage
var body: some View {
NavigationView {
List(storage.dailyMeasurementCounts) { day in
NavigationLink(destination: {
2023-06-14 17:52:43 +02:00
DayView(dateIndex: day.dateIndex)
.environmentObject(storage)
}) {
HistoryListRow(entry: day)
2023-06-13 17:14:57 +02:00
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
deleteRow(for: day.dateIndex)
} label: {
2023-06-14 17:52:43 +02:00
Label("Delete", systemSymbol: .trash)
2023-06-13 17:14:57 +02:00
}
2023-06-14 17:52:43 +02:00
.tint(.red)
2023-06-13 17:14:57 +02:00
}
}
}
.navigationTitle("History")
.navigationBarTitleDisplayMode(.large)
}
}
2023-06-13 17:14:57 +02:00
private func deleteRow(for dateIndex: Int) {
storage.removeMeasurements(for: dateIndex)
}
}
struct HistoryList_Previews: PreviewProvider {
static var previews: some View {
HistoryList()
.environmentObject(PersistentStorage(lastMeasurements: TemperatureMeasurement.mockData))
}
}