implement editing
This commit is contained in:
@@ -53,15 +53,21 @@ class ContentViewModel: ObservableObject {
|
||||
struct ContentView: View {
|
||||
@StateObject private var viewModel = ContentViewModel()
|
||||
@State private var isShowingAddSheet = false
|
||||
@State private var selectedStopwatch: Stopwatch?
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
ForEach(viewModel.stopwatches) { stopwatch in
|
||||
StopwatchRow(stopwatch: stopwatch, onDelete: {
|
||||
viewModel.deleteStopwatch(id: stopwatch.id)
|
||||
})
|
||||
Button {
|
||||
selectedStopwatch = stopwatch
|
||||
} label: {
|
||||
StopwatchRow(stopwatch: stopwatch, onDelete: {
|
||||
viewModel.deleteStopwatch(id: stopwatch.id)
|
||||
})
|
||||
}
|
||||
.buttonStyle(.plain) // Preserves the row layout and interactions
|
||||
}
|
||||
.onDelete { indexSet in
|
||||
for index in indexSet {
|
||||
@@ -86,6 +92,19 @@ struct ContentView: View {
|
||||
isShowingAddSheet = false
|
||||
}
|
||||
}
|
||||
.sheet(item: $selectedStopwatch) { stopwatch in
|
||||
StopwatchDetailView(
|
||||
stopwatch: stopwatch,
|
||||
onSave: { newName in
|
||||
stopwatch.name = newName
|
||||
viewModel.save()
|
||||
selectedStopwatch = nil
|
||||
},
|
||||
onCancel: {
|
||||
selectedStopwatch = nil
|
||||
}
|
||||
)
|
||||
}
|
||||
.overlay {
|
||||
if viewModel.stopwatches.isEmpty {
|
||||
ContentUnavailableView(
|
||||
|
||||
Reference in New Issue
Block a user