From 451fb3df264651f5f98d9b1c8927f14b2c8a2d69 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 23 Feb 2026 17:31:47 +0100 Subject: [PATCH] Fix HomeView data staleness on new watch entries, tab switches, and settings dismissal Post watchHistoryDidChange notification when a new watch entry is inserted during local playback progress updates (but not on every progress tick). Reload Home data when switching back to the Home tab and when the Customize Home sheet is dismissed. --- Yattee/Data/DataManager+WatchHistory.swift | 5 ++++- Yattee/Views/Home/HomeView.swift | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Yattee/Data/DataManager+WatchHistory.swift b/Yattee/Data/DataManager+WatchHistory.swift index e9ba8798..cdc96422 100644 --- a/Yattee/Data/DataManager+WatchHistory.swift +++ b/Yattee/Data/DataManager+WatchHistory.swift @@ -23,6 +23,7 @@ extension DataManager { let existing = try modelContext.fetch(descriptor) if let existingEntry = existing.first { existingEntry.updateProgress(seconds: seconds, duration: duration) + save() } else { let newEntry = WatchEntry.from(video: video) newEntry.watchedSeconds = seconds @@ -30,8 +31,10 @@ extension DataManager { newEntry.duration = duration } modelContext.insert(newEntry) + save() + // Notify HomeView when a new entry is inserted (not on every progress update) + NotificationCenter.default.post(name: .watchHistoryDidChange, object: nil) } - save() // Note: No CloudKit queueing - use updateWatchProgress() when sync is needed } catch { LoggingService.shared.logCloudKitError("Failed to update watch progress locally", error: error) diff --git a/Yattee/Views/Home/HomeView.swift b/Yattee/Views/Home/HomeView.swift index bf8a0009..e2866ac1 100644 --- a/Yattee/Views/Home/HomeView.swift +++ b/Yattee/Views/Home/HomeView.swift @@ -134,6 +134,16 @@ struct HomeView: View { loadData() } } + .onChange(of: appEnvironment?.navigationCoordinator.selectedTab) { _, newTab in + if newTab == .home { + loadData() + } + } + .onChange(of: showingCustomizeHome) { _, isShowing in + if !isShowing { + loadData() + } + } .onReceive(NotificationCenter.default.publisher(for: .bookmarksDidChange)) { _ in loadBookmarksData() }