From 1a1147b612f78aa6c94dc1e8be407d33063fdeaa Mon Sep 17 00:00:00 2001 From: rzen Date: Sat, 11 Jul 2026 12:40:18 -0400 Subject: [PATCH] Resolve the seed redirect when editing a schedule's routine A schedule made against a starter-seed routine keeps the retired seed id after the routine is edited (clone-on-edit). The edit form matched that id directly, so the routine read as unselected and Save stayed disabled; it now resolves through sync.currentRoutineID like the Today board does, and the routine picker's checkmark compares against the resolved id. --- Workouts/Views/Today/ScheduleAddEditView.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Workouts/Views/Today/ScheduleAddEditView.swift b/Workouts/Views/Today/ScheduleAddEditView.swift index f5ad674..2be4928 100644 --- a/Workouts/Views/Today/ScheduleAddEditView.swift +++ b/Workouts/Views/Today/ScheduleAddEditView.swift @@ -117,8 +117,14 @@ struct ScheduleAddEditView: View { private var isEditing: Bool { scheduleID != nil } - /// The live routine currently selected; nil when the stored id no longer resolves. - private var selectedRoutine: Routine? { routines.first { $0.id == routineID } } + /// The live routine currently selected, following the seed clone-on-edit redirect + /// (a schedule made against a starter seed keeps the retired seed id after the + /// routine is edited); nil when the routine has been deleted. + private var selectedRoutine: Routine? { + guard !routineID.isEmpty else { return nil } + let liveID = sync.currentRoutineID(for: routineID) + return routines.first { $0.id == liveID } + } /// The When choices this presentation offers — "Now" only when adding on today. /// Built as a list (rather than conditionally hiding a tag inside the Picker) @@ -171,7 +177,8 @@ struct ScheduleAddEditView: View { private var routineSection: some View { Section { NavigationLink { - RoutinePickerList(routines: routines, selectedID: $routineID) + RoutinePickerList(routines: routines, currentID: selectedRoutine?.id, + selectedID: $routineID) } label: { HStack { Text("Routine") @@ -333,6 +340,9 @@ struct ScheduleAddEditView: View { /// Tapping selects and pops back. private struct RoutinePickerList: View { let routines: [Routine] + /// The resolved live id of the current selection (for the checkmark) — may differ + /// from the binding's stored value when a seed clone-on-edit redirect is in play. + let currentID: String? @Binding var selectedID: String @Environment(\.dismiss) private var dismiss @@ -350,7 +360,7 @@ private struct RoutinePickerList: View { Text(routine.name) .foregroundStyle(.primary) Spacer() - if routine.id == selectedID { + if routine.id == currentID { Image(systemName: "checkmark") .fontWeight(.semibold) .foregroundStyle(Color.accentColor)