From 7fbd320fa75f5e645e63fae70f8674ed78fec5e6 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sun, 9 Nov 2025 16:52:00 +0100 Subject: [PATCH] fix: full refresh on profile switch --- lib/screens/discover_screen.dart | 9 ++++++++- lib/screens/libraries_screen.dart | 12 +++++++++++- lib/screens/main_screen.dart | 18 +++++++++--------- lib/screens/search_screen.dart | 14 ++++++++++++++ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/lib/screens/discover_screen.dart b/lib/screens/discover_screen.dart index b55d3b50..86e68736 100644 --- a/lib/screens/discover_screen.dart +++ b/lib/screens/discover_screen.dart @@ -273,7 +273,7 @@ class _DiscoverScreenState extends State } } - // Public method to refresh content + // Public method to refresh content (for normal navigation) @override void refresh() { appLogger.d('DiscoverScreen.refresh() called'); @@ -281,6 +281,13 @@ class _DiscoverScreenState extends State _refreshContinueWatching(); } + // Public method to fully reload all content (for profile switches) + void fullRefresh() { + appLogger.d('DiscoverScreen.fullRefresh() called - reloading all content'); + // Reload all content including Recently Added and content hubs + _loadContent(); + } + /// Get icon for hub based on its title IconData _getHubIcon(String title) { final lowerTitle = title.toLowerCase(); diff --git a/lib/screens/libraries_screen.dart b/lib/screens/libraries_screen.dart index 4feba0d3..55e34cd6 100644 --- a/lib/screens/libraries_screen.dart +++ b/lib/screens/libraries_screen.dart @@ -503,12 +503,22 @@ class _LibrariesScreenState extends State } } - // Public method to refresh content + // Public method to refresh content (for normal navigation) @override void refresh() { _loadLibraries(); } + // Public method to fully reload all content (for profile switches) + void fullRefresh() { + appLogger.d('LibrariesScreen.fullRefresh() called - reloading all content'); + // Reload libraries and clear any selected library/filters + _selectedLibraryKey = null; + _selectedFilters.clear(); + _items.clear(); + _loadLibraries(); + } + Future _toggleLibraryVisibility(PlexLibrary library) async { final hiddenLibrariesProvider = Provider.of( context, diff --git a/lib/screens/main_screen.dart b/lib/screens/main_screen.dart index e7da3156..6532a4e6 100644 --- a/lib/screens/main_screen.dart +++ b/lib/screens/main_screen.dart @@ -93,22 +93,22 @@ class _MainScreenState extends State with RouteAware { void _invalidateAllScreens() { appLogger.d('Invalidating all screen data due to profile switch'); - // Refresh discover screen + // Full refresh discover screen (reload all content for new profile) final discoverState = _discoverKey.currentState; - if (discoverState != null && discoverState is Refreshable) { - (discoverState as Refreshable).refresh(); + if (discoverState != null) { + (discoverState as dynamic).fullRefresh(); } - // Refresh libraries screen + // Full refresh libraries screen (clear filters and reload for new profile) final librariesState = _librariesKey.currentState; - if (librariesState != null && librariesState is Refreshable) { - (librariesState as Refreshable).refresh(); + if (librariesState != null) { + (librariesState as dynamic).fullRefresh(); } - // Refresh search screen + // Full refresh search screen (clear search for new profile) final searchState = _searchKey.currentState; - if (searchState != null && searchState is Refreshable) { - (searchState as Refreshable).refresh(); + if (searchState != null) { + (searchState as dynamic).fullRefresh(); } } diff --git a/lib/screens/search_screen.dart b/lib/screens/search_screen.dart index 39c26769..e98a154e 100644 --- a/lib/screens/search_screen.dart +++ b/lib/screens/search_screen.dart @@ -6,6 +6,7 @@ import '../models/plex_metadata.dart'; import '../services/settings_service.dart'; import '../providers/settings_provider.dart'; import '../utils/provider_extensions.dart'; +import '../utils/app_logger.dart'; import '../widgets/media_card.dart'; import '../widgets/desktop_app_bar.dart'; import '../mixins/refreshable.dart'; @@ -120,6 +121,19 @@ class _SearchScreenState extends State } } + // Public method to fully reload all content (for profile switches) + void fullRefresh() { + appLogger.d('SearchScreen.fullRefresh() called - clearing search and reloading'); + // Clear search results and search text for new profile + _searchController.clear(); + setState(() { + _searchResults.clear(); + _isSearching = false; + _hasSearched = false; + _lastSearchedQuery = ''; + }); + } + @override void updateItemInLists(String ratingKey, PlexMetadata updatedMetadata) { final index = _searchResults.indexWhere(