2023-06-08 09:52:20 +02:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct HistoryList: View {
|
|
|
|
|
|
|
|
@EnvironmentObject
|
2023-07-02 17:29:39 +02:00
|
|
|
var storage: PersistentStorage
|
2023-06-08 09:52:20 +02:00
|
|
|
|
|
|
|
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)
|
2023-06-08 09:52:20 +02:00
|
|
|
}) {
|
|
|
|
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
|
|
|
}
|
2023-06-08 09:52:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationTitle("History")
|
|
|
|
.navigationBarTitleDisplayMode(.large)
|
|
|
|
}
|
|
|
|
}
|
2023-06-13 17:14:57 +02:00
|
|
|
|
|
|
|
private func deleteRow(for dateIndex: Int) {
|
|
|
|
storage.removeMeasurements(for: dateIndex)
|
|
|
|
}
|
2023-06-08 09:52:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct HistoryList_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
HistoryList()
|
2023-07-02 17:29:39 +02:00
|
|
|
.environmentObject(PersistentStorage(lastMeasurements: TemperatureMeasurement.mockData))
|
2023-06-08 09:52:20 +02:00
|
|
|
}
|
|
|
|
}
|