implement alerts, delete

This commit is contained in:
2026-01-28 23:43:50 +01:00
parent a607e33ce9
commit 93cf6f8483
3 changed files with 51 additions and 9 deletions

View File

@@ -12,9 +12,11 @@ struct StopwatchDetailView: View {
let onSave: (String) -> Void
let onCancel: () -> Void
let onReset: () -> Void
let onDelete: () -> Void
@State private var draftName: String
@State private var isShowingResetAlert = false
@State private var isShowingDeleteAlert = false
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
@@ -22,11 +24,12 @@ struct StopwatchDetailView: View {
return formatter
}()
init(stopwatch: Stopwatch, onSave: @escaping (String) -> Void, onCancel: @escaping () -> Void, onReset: @escaping () -> Void) {
init(stopwatch: Stopwatch, onSave: @escaping (String) -> Void, onCancel: @escaping () -> Void, onReset: @escaping () -> Void, onDelete: @escaping () -> Void) {
self.stopwatch = stopwatch
self.onSave = onSave
self.onCancel = onCancel
self.onReset = onReset
self.onDelete = onDelete
_draftName = State(initialValue: stopwatch.name)
}
@@ -112,6 +115,18 @@ struct StopwatchDetailView: View {
}
}
}
Section {
Button(role: .destructive) {
isShowingDeleteAlert = true
} label: {
HStack {
Spacer()
Text("Delete Stopwatch")
Spacer()
}
}
}
}
.navigationTitle("Edit Stopwatch")
.navigationBarTitleDisplayMode(.inline)
@@ -121,6 +136,12 @@ struct StopwatchDetailView: View {
}
Button("Cancel", role: .cancel) {}
}
.alert("Are you sure you want to delete the Stopwatch \(stopwatch.name)?", isPresented: $isShowingDeleteAlert) {
Button("Delete", role: .destructive) {
onDelete()
}
Button("Cancel", role: .cancel) {}
}
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
@@ -143,6 +164,7 @@ struct StopwatchDetailView: View {
stopwatch: Stopwatch(name: "Test Timer"),
onSave: { _ in },
onCancel: {},
onReset: {}
onReset: {},
onDelete: {}
)
}