Stabilize planner UI, fix reset flow, and force Premium on TestFlight
This commit is contained in:
@@ -68,26 +68,43 @@ final class SettingsViewModel: ObservableObject {
|
||||
|
||||
func resetAllData(context: ModelContext) {
|
||||
do {
|
||||
// WeekPlan cascades MealSlot, so deleting both can corrupt the reset flow.
|
||||
try deleteAll(of: WeekPlan.self, in: context)
|
||||
try deleteAll(of: Dish.self, in: context)
|
||||
try deleteAll(of: Tag.self, in: context)
|
||||
DefaultDataService.createDefaultTags(context: context, saveImmediately: false)
|
||||
|
||||
let settingsDescriptor = FetchDescriptor<AppSettings>()
|
||||
let targetSettings: AppSettings
|
||||
|
||||
if let existingSettings = try context.fetch(settingsDescriptor).first {
|
||||
resetSettings(existingSettings)
|
||||
targetSettings = existingSettings
|
||||
} else {
|
||||
DefaultDataService.createDefaultSettings(context: context)
|
||||
if let createdSettings = try context.fetch(settingsDescriptor).first {
|
||||
resetSettings(createdSettings)
|
||||
}
|
||||
let created = AppSettings()
|
||||
context.insert(created)
|
||||
targetSettings = created
|
||||
}
|
||||
|
||||
// Phase 1: switch app flow out of Home before destructive deletes.
|
||||
resetSettings(targetSettings)
|
||||
try context.save()
|
||||
|
||||
Task { @MainActor in
|
||||
do {
|
||||
try? await Task.sleep(nanoseconds: 200_000_000)
|
||||
|
||||
try deleteAll(of: WeekPlan.self, in: context)
|
||||
try deleteAll(of: Dish.self, in: context)
|
||||
try deleteAll(of: Tag.self, in: context)
|
||||
DefaultDataService.createDefaultTags(context: context, saveImmediately: false)
|
||||
|
||||
// Ensure a true "fresh launch" onboarding flow.
|
||||
UserDefaults.standard.set(false, forKey: OnboardingViewModel.pendingAutoAssignPromptKey)
|
||||
UserDefaults.standard.set(false, forKey: OnboardingViewModel.pendingPremiumPromptKey)
|
||||
try context.save()
|
||||
} catch {
|
||||
#if DEBUG
|
||||
print("Failed to complete reset all data: \(error)")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
#if DEBUG
|
||||
print("Failed to reset all data: \(error)")
|
||||
print("Failed to start reset all data: \(error)")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user