fix(sync): add foreground sync, remove manual sync button

- Add scenePhase observer to sync when app returns to foreground
- Remove misleading "Sync Schedules" button from Settings (it only
  reloaded local data, didn't actually sync from CloudKit)
- Fix GamesHistoryView to refresh list after deleting a visit

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-12 22:04:10 -06:00
parent 0524284ab8
commit ba3ea6daeb
4 changed files with 19 additions and 77 deletions

View File

@@ -59,8 +59,10 @@ struct SportsTimeApp: App {
struct BootstrappedContentView: View {
let modelContainer: ModelContainer
@Environment(\.scenePhase) private var scenePhase
@State private var isBootstrapping = true
@State private var bootstrapError: Error?
@State private var hasCompletedInitialSync = false
var body: some View {
Group {
@@ -79,6 +81,14 @@ struct BootstrappedContentView: View {
.task {
await performBootstrap()
}
.onChange(of: scenePhase) { _, newPhase in
// Sync when app comes to foreground (but not on initial launch)
if newPhase == .active && hasCompletedInitialSync {
Task {
await performBackgroundSync(context: modelContainer.mainContext)
}
}
}
}
@MainActor
@@ -105,6 +115,9 @@ struct BootstrappedContentView: View {
// 5. Background: Try to refresh from CloudKit (non-blocking)
Task.detached(priority: .background) {
await self.performBackgroundSync(context: context)
await MainActor.run {
self.hasCompletedInitialSync = true
}
}
} catch {
bootstrapError = error