Release 1.0.0 baseline
This commit is contained in:
@@ -42,10 +42,14 @@ struct OnboardingView: View {
|
||||
.tag(2)
|
||||
|
||||
CalendarStepView(
|
||||
iCloudSyncEnabled: $viewModel.syncICloud,
|
||||
syncEnabled: $viewModel.syncCalendar,
|
||||
selectedCalendarId: $viewModel.selectedCalendarId,
|
||||
lunchTime: $viewModel.lunchTime,
|
||||
dinnerTime: $viewModel.dinnerTime,
|
||||
onEnableICloud: {
|
||||
Task { await restoreFromICloudAndFinishIfNeeded() }
|
||||
},
|
||||
onNext: { viewModel.nextStep() },
|
||||
onSkip: { viewModel.nextStep() }
|
||||
)
|
||||
@@ -68,6 +72,7 @@ struct OnboardingView: View {
|
||||
}
|
||||
.onAppear {
|
||||
ensureDefaultTagsIfNeeded()
|
||||
Task { await restoreFromICloudAndFinishIfNeeded() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,4 +82,28 @@ struct OnboardingView: View {
|
||||
DefaultDataService.createDefaultTags(context: context)
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFromICloudAndFinishIfNeeded() async {
|
||||
let settingsDescriptor = FetchDescriptor<AppSettings>()
|
||||
let currentSettings = (try? context.fetch(settingsDescriptor))?.first
|
||||
let iCloudEnabled = currentSettings?.iCloudSyncEnabledResolved ?? viewModel.syncICloud
|
||||
guard iCloudEnabled else { return }
|
||||
|
||||
await ICloudSyncService.shared.pullRemoteIfNeeded(context: context)
|
||||
|
||||
guard shouldAutoCompleteOnboarding() else { return }
|
||||
if let settings = (try? context.fetch(settingsDescriptor))?.first, !settings.onboardingCompleted {
|
||||
settings.onboardingCompleted = true
|
||||
try? context.save()
|
||||
}
|
||||
onComplete()
|
||||
}
|
||||
|
||||
private func shouldAutoCompleteOnboarding() -> Bool {
|
||||
let dishes = (try? context.fetch(FetchDescriptor<Dish>())) ?? []
|
||||
if !dishes.isEmpty { return true }
|
||||
|
||||
let plans = (try? context.fetch(FetchDescriptor<WeekPlan>())) ?? []
|
||||
return !plans.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user