TempTrack-iOS/TempTrack/Views/HistoryList.swift
2023-06-13 17:14:57 +02:00

41 lines
1.2 KiB
Swift

import SwiftUI
struct HistoryList: View {
@EnvironmentObject
var storage: TemperatureStorage
var body: some View {
NavigationView {
List(storage.dailyMeasurementCounts) { day in
NavigationLink(destination: {
TemperatureDayOverview(storage: storage, dateIndex: day.dateIndex)
}) {
HistoryListRow(entry: day)
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button {
deleteRow(for: day.dateIndex)
} label: {
Label("Delete", systemSymbol: .pencil)
}
.tint(.purple)
}
}
}
.navigationTitle("History")
.navigationBarTitleDisplayMode(.large)
}
}
private func deleteRow(for dateIndex: Int) {
storage.removeMeasurements(for: dateIndex)
}
}
struct HistoryList_Previews: PreviewProvider {
static var previews: some View {
HistoryList()
.environmentObject(TemperatureStorage(lastMeasurements: TemperatureMeasurement.mockData))
}
}