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.
This commit is contained in:
@@ -117,8 +117,14 @@ struct ScheduleAddEditView: View {
|
|||||||
|
|
||||||
private var isEditing: Bool { scheduleID != nil }
|
private var isEditing: Bool { scheduleID != nil }
|
||||||
|
|
||||||
/// The live routine currently selected; nil when the stored id no longer resolves.
|
/// The live routine currently selected, following the seed clone-on-edit redirect
|
||||||
private var selectedRoutine: Routine? { routines.first { $0.id == routineID } }
|
/// (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.
|
/// 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)
|
/// 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 {
|
private var routineSection: some View {
|
||||||
Section {
|
Section {
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
RoutinePickerList(routines: routines, selectedID: $routineID)
|
RoutinePickerList(routines: routines, currentID: selectedRoutine?.id,
|
||||||
|
selectedID: $routineID)
|
||||||
} label: {
|
} label: {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Routine")
|
Text("Routine")
|
||||||
@@ -333,6 +340,9 @@ struct ScheduleAddEditView: View {
|
|||||||
/// Tapping selects and pops back.
|
/// Tapping selects and pops back.
|
||||||
private struct RoutinePickerList: View {
|
private struct RoutinePickerList: View {
|
||||||
let routines: [Routine]
|
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
|
@Binding var selectedID: String
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
|
||||||
@@ -350,7 +360,7 @@ private struct RoutinePickerList: View {
|
|||||||
Text(routine.name)
|
Text(routine.name)
|
||||||
.foregroundStyle(.primary)
|
.foregroundStyle(.primary)
|
||||||
Spacer()
|
Spacer()
|
||||||
if routine.id == selectedID {
|
if routine.id == currentID {
|
||||||
Image(systemName: "checkmark")
|
Image(systemName: "checkmark")
|
||||||
.fontWeight(.semibold)
|
.fontWeight(.semibold)
|
||||||
.foregroundStyle(Color.accentColor)
|
.foregroundStyle(Color.accentColor)
|
||||||
|
|||||||
Reference in New Issue
Block a user