Stabilize planner UI, fix reset flow, and force Premium on TestFlight
This commit is contained in:
@@ -429,6 +429,33 @@ final class HomeViewModel: ObservableObject {
|
||||
}
|
||||
}()
|
||||
|
||||
// Clean up any legacy duplicates for the same day+mealType key to keep UI mapping stable.
|
||||
var groupedByKey: [SlotKey: [MealSlot]] = [:]
|
||||
for slot in plan.slots {
|
||||
let key = SlotKey(dayOfWeek: slot.dayOfWeek, mealType: slot.mealType)
|
||||
groupedByKey[key, default: []].append(slot)
|
||||
}
|
||||
|
||||
var changed = false
|
||||
for (_, duplicates) in groupedByKey where duplicates.count > 1 {
|
||||
let keeper = MealSlot.preferredForDuplicateResolution(duplicates)
|
||||
for duplicate in duplicates where duplicate.id != keeper.id {
|
||||
if keeper.dishId == nil, let dishId = duplicate.dishId {
|
||||
keeper.dishId = dishId
|
||||
keeper.isRuleOverridden = duplicate.isRuleOverridden
|
||||
if keeper.calendarEventId == nil {
|
||||
keeper.calendarEventId = duplicate.calendarEventId
|
||||
}
|
||||
} else if let duplicateEventId = duplicate.calendarEventId {
|
||||
CalendarService.shared.deleteEvent(eventId: duplicateEventId)
|
||||
}
|
||||
|
||||
plan.slots.removeAll { $0.id == duplicate.id }
|
||||
context.delete(duplicate)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
var desired = Set<SlotKey>()
|
||||
for day in 0...maxDay {
|
||||
for mealType in mealTypes {
|
||||
@@ -443,7 +470,6 @@ final class HomeViewModel: ObservableObject {
|
||||
existingByKey[key] = slot
|
||||
}
|
||||
}
|
||||
var changed = false
|
||||
|
||||
let toDelete = plan.slots.filter { slot in
|
||||
!desired.contains(SlotKey(dayOfWeek: slot.dayOfWeek, mealType: slot.mealType))
|
||||
|
||||
Reference in New Issue
Block a user