implement editing
This commit is contained in:
56
MultiChrono/StopwatchDetailView.swift
Normal file
56
MultiChrono/StopwatchDetailView.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// StopwatchDetailView.swift
|
||||
// MultiChrono
|
||||
//
|
||||
// Created by Beatrice Dellacà on 27/01/26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct StopwatchDetailView: View {
|
||||
let stopwatch: Stopwatch
|
||||
let onSave: (String) -> Void
|
||||
let onCancel: () -> Void
|
||||
|
||||
@State private var draftName: String
|
||||
|
||||
init(stopwatch: Stopwatch, onSave: @escaping (String) -> Void, onCancel: @escaping () -> Void) {
|
||||
self.stopwatch = stopwatch
|
||||
self.onSave = onSave
|
||||
self.onCancel = onCancel
|
||||
_draftName = State(initialValue: stopwatch.name)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section(header: Text("Name")) {
|
||||
TextField("Enter name...", text: $draftName)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Edit Stopwatch")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel") {
|
||||
onCancel()
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Save") {
|
||||
onSave(draftName)
|
||||
}
|
||||
.disabled(draftName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
StopwatchDetailView(
|
||||
stopwatch: Stopwatch(name: "Test Timer"),
|
||||
onSave: { _ in },
|
||||
onCancel: {}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user