From 90e4db2e8a27f8cf85e474b0f8a081b70f41bdb1 Mon Sep 17 00:00:00 2001 From: Tushar Jain Date: Tue, 5 Mar 2024 22:48:05 +0530 Subject: [PATCH] feat: add family providers --- lib/providers/auth.dart | 9 +- lib/providers/index.dart | 2 + lib/providers/matches.dart | 249 +-------------- lib/providers/players.dart | 300 ++++++++++-------- lib/providers/search.dart | 134 ++++++++ lib/providers/top_matches.dart | 38 +++ lib/screens/active_match/active_match.dart | 27 +- .../active_match/active_match_list.dart | 10 +- .../active_match/active_match_player.dart | 2 +- lib/screens/app_drawer/app_drawer.dart | 2 - .../common_matches/common_matches.dart | 24 +- .../common_matches/common_matches_header.dart | 10 +- .../common_matches/common_matches_list.dart | 4 +- lib/screens/friends/friend_item.dart | 2 +- lib/screens/friends/friends.dart | 27 +- lib/screens/friends/friends_app_bar.dart | 18 +- lib/screens/global_chat/global_chat.dart | 2 +- lib/screens/home/home.dart | 6 +- lib/screens/home/home_top_matches.dart | 8 +- .../leaderboard/leaderboard_player.dart | 2 +- lib/screens/loadouts/loadouts.dart | 14 +- lib/screens/match_detail/match_detail.dart | 3 +- .../match_detail/match_detail_list.dart | 13 +- .../match_detail_player_card.dart | 2 +- .../player_champions/player_champions.dart | 12 +- lib/screens/player_detail/player_detail.dart | 59 ++-- .../player_detail_filter_modal.dart | 17 +- .../player_detail_filter_tab.dart | 18 +- .../player_detail/player_detail_header.dart | 23 +- ...player_detail_header_expandable_panel.dart | 28 +- .../player_detail_match_card.dart | 2 +- .../player_detail/player_detail_matches.dart | 19 +- .../player_detail/player_detail_menu.dart | 25 +- .../player_detail/player_detail_sort_tab.dart | 14 +- .../player_detail_status_indicator.dart | 20 +- lib/screens/search/search.dart | 16 +- lib/screens/search/search_app_bar.dart | 4 +- lib/screens/search/search_history.dart | 2 +- lib/screens/search/search_lower_list.dart | 5 +- lib/screens/search/search_top_list.dart | 5 +- lib/widgets/connect_player_modal.dart | 13 +- 41 files changed, 613 insertions(+), 577 deletions(-) create mode 100644 lib/providers/search.dart create mode 100644 lib/providers/top_matches.dart diff --git a/lib/providers/auth.dart b/lib/providers/auth.dart index 9e65ae44..70bd839d 100644 --- a/lib/providers/auth.dart +++ b/lib/providers/auth.dart @@ -132,6 +132,8 @@ class _AuthNotifier extends ChangeNotifier { final firebaseAuthResponse = await _getFirebaseAuthCredentials(); final idToken = firebaseAuthResponse.idToken; + print("ID TOKEN : $idToken"); + if (firebaseAuthResponse.errorCode == 0) { // user has closed the popup window return data_classes.SignInProviderResponse(result: false); @@ -212,9 +214,8 @@ class _AuthNotifier extends ChangeNotifier { clearData(); ref.read(providers.champions).clearData(); ref.read(providers.loadout).clearData(); - ref.read(providers.matches).clearData(); - ref.read(providers.players).clearData(); ref.read(providers.appState).clearData(); + ref.read(providers.search).clearData(); // clear values from the database and utilities utilities.Database.clear(); @@ -311,7 +312,7 @@ class _AuthNotifier extends ChangeNotifier { (_) => _.match.matchId == matchId, ); if (combinedMatch == null) { - final matchDetails = ref.read(providers.matches).matchDetails; + final matchDetails = ref.read(providers.matches(matchId)).matchDetails; if (matchDetails != null && matchDetails.match.matchId == matchId) { combinedMatch = data_classes.CombinedMatch( match: matchDetails.match, @@ -433,6 +434,7 @@ class _AuthNotifier extends ChangeNotifier { try { googleUser = await GoogleSignIn().signIn(); } catch (error) { + print("Error 1 :: ${error.toString()}"); if (error is PlatformException) { return _GetFirebaseAuthResponse( errorCode: 0, @@ -457,6 +459,7 @@ class _AuthNotifier extends ChangeNotifier { try { googleAuth = await googleUser.authentication; } catch (error) { + print("Error 2 :: $error"); return _GetFirebaseAuthResponse( errorCode: 3, errorMessage: error.toString(), diff --git a/lib/providers/index.dart b/lib/providers/index.dart index afe7d50c..214c2257 100644 --- a/lib/providers/index.dart +++ b/lib/providers/index.dart @@ -11,3 +11,5 @@ export "./loadout.dart"; export "./matches.dart"; export "./players.dart"; export "./queue.dart"; +export "./search.dart"; +export "./top_matches.dart"; diff --git a/lib/providers/matches.dart b/lib/providers/matches.dart index 932b4431..8f9db10d 100644 --- a/lib/providers/matches.dart +++ b/lib/providers/matches.dart @@ -1,103 +1,22 @@ import "package:flutter/foundation.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:paladinsedge/api/index.dart" as api; -import "package:paladinsedge/data_classes/index.dart" as data_classes; -import "package:paladinsedge/models/index.dart" as models; -import "package:paladinsedge/providers/champions.dart" as champions_provider; import "package:paladinsedge/utilities/index.dart" as utilities; class _MatchesNotifier extends ChangeNotifier { + final String matchId; final ChangeNotifierProviderRef<_MatchesNotifier> ref; /// Match detail bool isMatchDetailsLoading = false; api.MatchDetailsResponse? matchDetails; - /// Player matches - bool isPlayerMatchesLoading = false; - String? combinedMatchesPlayerId; - List? combinedMatches; - int? playerStreak; + _MatchesNotifier({ + required this.matchId, + required this.ref, + }); - /// Common matches - bool isCommonMatchesLoading = false; - String? commonMatchesPlayerId; - List? commonMatches; - - /// Top matches - bool isTopMatchesLoading = true; - List? topMatches; - - /// Matches filter and sorting - String selectedSort = data_classes.MatchSort.defaultSort; - data_classes.SelectedMatchFilter selectedFilter = - data_classes.SelectedMatchFilter(); - - _MatchesNotifier({required this.ref}); - - void resetPlayerMatches({bool forceUpdate = false}) { - if (forceUpdate) return; - - isPlayerMatchesLoading = true; - combinedMatches = null; - combinedMatchesPlayerId = null; - playerStreak = null; - utilities.postFrameCallback(notifyListeners); - } - - /// get the matches for this playerId - Future getPlayerMatches({ - required String playerId, - bool forceUpdate = false, - }) async { - final response = await api.MatchRequests.playerMatches( - playerId: playerId, - forceUpdate: forceUpdate, - ); - if (!forceUpdate) isPlayerMatchesLoading = false; - - if (response == null) return notifyListeners(); - - // create list of combinedMatches using a temp. map - final Map tempMatchesMap = {}; - for (final match in response.matches) { - tempMatchesMap[match.matchId] = data_classes.CombinedMatch( - match: match, - matchPlayers: [], - ); - } - for (final matchPlayer in response.matchPlayers) { - final existingCombinedMatch = tempMatchesMap[matchPlayer.matchId]; - if (existingCombinedMatch == null) continue; - - tempMatchesMap[matchPlayer.matchId] = existingCombinedMatch.copyWith( - matchPlayers: [...existingCombinedMatch.matchPlayers, matchPlayer], - ); - } - - combinedMatchesPlayerId = playerId; - combinedMatches = tempMatchesMap.values.toList(); - - // sort combinedMatches based on the selectedSort - if (combinedMatches != null) { - combinedMatches = data_classes.MatchSort.getSortedMatches( - combinedMatches: combinedMatches!, - sort: selectedSort, - ); - } - - // get the playerStreak - playerStreak = utilities.getPlayerStreak( - combinedMatches, - combinedMatchesPlayerId, - ); - - if (!forceUpdate) isPlayerMatchesLoading = false; - - notifyListeners(); - } - - Future getMatchDetails(String matchId) async { + Future getMatchDetails() async { isMatchDetailsLoading = true; utilities.postFrameCallback(notifyListeners); @@ -109,25 +28,6 @@ class _MatchesNotifier extends ChangeNotifier { // sort players based on their team matchDetails?.matchPlayers.sort((a, b) => a.team.compareTo(b.team)); - final index = combinedMatches?.indexWhere( - (combinedMatch) => - combinedMatch.match.matchId == matchDetails?.match.matchId, - ); - if (index != null && - index >= 0 && - combinedMatches != null && - matchDetails != null) { - final combinedMatch = combinedMatches!.elementAt(index); - if (combinedMatch.match.isInComplete) { - combinedMatches![index] = data_classes.CombinedMatch( - match: matchDetails!.match, - matchPlayers: matchDetails!.matchPlayers, - hide: combinedMatch.hide, - ); - combinedMatches = [...combinedMatches!]; - } - } - notifyListeners(); } @@ -137,147 +37,14 @@ class _MatchesNotifier extends ChangeNotifier { utilities.postFrameCallback(notifyListeners); } - /// Set value of sort and apply sorting - void setSort(String sort) { - if (combinedMatches == null) return; - - selectedSort = sort; - combinedMatches = data_classes.MatchSort.getSortedMatches( - combinedMatches: combinedMatches!, - sort: sort, - ); - - notifyListeners(); - } - - /// Set value of filter and apply the filter - void setFilterValue( - String? filterName, - data_classes.MatchFilterValue? filterValue, - ) { - if (combinedMatches == null || combinedMatchesPlayerId == null) return; - - selectedFilter = data_classes.SelectedMatchFilter( - name: filterName, - value: filterValue, - ); - final champions = ref.read(champions_provider.champions).champions; - - combinedMatches = selectedFilter.isValid - ? data_classes.MatchFilter.getFilteredMatches( - combinedMatches: combinedMatches!, - filter: selectedFilter, - champions: champions, - playerId: combinedMatchesPlayerId!, - ) - : data_classes.MatchFilter.clearFilters(combinedMatches!); - - notifyListeners(); - } - - void getCommonMatches({ - required String userPlayerId, - required String playerId, - }) async { - isCommonMatchesLoading = true; - commonMatchesPlayerId = playerId; - utilities.postFrameCallback(notifyListeners); - - final response = await api.MatchRequests.commonMatches( - playerIds: [userPlayerId, playerId], - ); - if (response == null) { - isCommonMatchesLoading = false; - commonMatches = null; - notifyListeners(); - - return; - } - - // create list of commonMatches using a temp. map - final Map tempMatchesMap = {}; - for (final match in response.matches) { - tempMatchesMap[match.matchId] = data_classes.CombinedMatch( - match: match, - matchPlayers: [], - ); - } - for (final matchPlayer in response.matchPlayers) { - final existingCombinedMatch = tempMatchesMap[matchPlayer.matchId]; - if (existingCombinedMatch == null) continue; - - tempMatchesMap[matchPlayer.matchId] = existingCombinedMatch.copyWith( - matchPlayers: [...existingCombinedMatch.matchPlayers, matchPlayer], - ); - } - - isCommonMatchesLoading = false; - commonMatches = tempMatchesMap.values.toList(); - - // sort commonMatches based on date - if (commonMatches != null) { - commonMatches = data_classes.MatchSort.getSortedMatches( - combinedMatches: commonMatches!, - sort: data_classes.MatchSort.defaultSort, - ); - } - - notifyListeners(); - } - - /// Clears all applied filters and sort on combinedMatches - void clearAppliedFiltersAndSort() { - if (combinedMatches == null) return; - - combinedMatches = data_classes.MatchFilter.clearFilters(combinedMatches!); - combinedMatches = data_classes.MatchSort.clearSorting(combinedMatches!); - selectedFilter = data_classes.SelectedMatchFilter( - name: selectedFilter.name, - ); - selectedSort = data_classes.MatchSort.defaultSort; - - utilities.postFrameCallback(notifyListeners); - } - - /// Loads the `topMatches` data from local db and syncs it with server - Future loadTopMatches(bool forceUpdate) async { - final savedTopMatches = - forceUpdate ? null : utilities.Database.getTopMatches(); - - if (savedTopMatches != null) { - isTopMatchesLoading = false; - topMatches = savedTopMatches; - - return utilities.postFrameCallback(notifyListeners); - } - - final response = await api.MatchRequests.topMatches(); - if (response == null) return; - - isTopMatchesLoading = false; - topMatches = response.topMatches; - notifyListeners(); - - // save topMatches locally for future use - // clear topMatches first if forceUpdate - if (forceUpdate) await utilities.Database.topMatchBox?.clear(); - topMatches?.forEach(utilities.Database.saveTopMatch); - } - /// Clears all user sensitive data upon logout void clearData() { - isPlayerMatchesLoading = false; isMatchDetailsLoading = false; - isCommonMatchesLoading = false; matchDetails = null; - combinedMatchesPlayerId = null; - combinedMatches = null; - commonMatchesPlayerId = null; - commonMatches = null; } } /// Provider to handle matches -final matches = ChangeNotifierProvider<_MatchesNotifier>( - (ref) => _MatchesNotifier(ref: ref), +final matches = ChangeNotifierProvider.family<_MatchesNotifier, String>( + (ref, matchId) => _MatchesNotifier(ref: ref, matchId: matchId), ); diff --git a/lib/providers/players.dart b/lib/providers/players.dart index 8dc4a35b..5211499e 100644 --- a/lib/providers/players.dart +++ b/lib/providers/players.dart @@ -1,29 +1,46 @@ import "package:flutter/foundation.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:paladinsedge/api/index.dart" as api; -import "package:paladinsedge/constants/index.dart" as constants; +import "package:paladinsedge/data_classes/index.dart" as data_classes; import "package:paladinsedge/models/index.dart" as models; +import "package:paladinsedge/providers/auth.dart" as auth_provider; +import "package:paladinsedge/providers/champions.dart" as champions_provider; +import "package:paladinsedge/providers/search.dart" as search_provider; import "package:paladinsedge/utilities/index.dart" as utilities; class _PlayersNotifier extends ChangeNotifier { + // Loading bool isLoadingPlayerData = false; bool isLoadingPlayerStatus = false; bool isLoadingPlayerInferred = false; + bool isPlayerMatchesLoading = false; + bool isCommonMatchesLoading = false; + + // Player related data + int? playerStreak; models.Player? playerData; api.PlayerStatusResponse? playerStatus; models.PlayerInferred? playerInferred; - List lowerSearchList = []; - List topSearchList = []; - List searchHistory = []; + List? combinedMatches; + List? commonMatches; + + /// Matches filter and sorting + String selectedSort = data_classes.MatchSort.defaultSort; + data_classes.SelectedMatchFilter selectedFilter = + data_classes.SelectedMatchFilter(); + + final String playerId; final ChangeNotifierProviderRef<_PlayersNotifier> ref; - _PlayersNotifier({required this.ref}); + _PlayersNotifier({ + required this.playerId, + required this.ref, + }); /// get the playerStatus from api /// [onlyStatus] param if false, will get the active match details as well /// else it will not get the active match details Future getPlayerStatus({ - required String playerId, bool forceUpdate = false, bool onlyStatus = false, }) async { @@ -49,9 +66,7 @@ class _PlayersNotifier extends ChangeNotifier { } /// get the playerInferred from the api - Future getPlayerInferred({ - required String playerId, - }) async { + Future getPlayerInferred() async { isLoadingPlayerInferred = true; utilities.postFrameCallback(notifyListeners); @@ -64,149 +79,185 @@ class _PlayersNotifier extends ChangeNotifier { notifyListeners(); } - /// Loads the `searchHistory` data for the user from local db and - /// syncs it with server for showing in Search screen - void loadSearchHistory() async { - // gets the search history from local db - final savedSearchHistory = utilities.Database.getSearchHistory(); - - // if searchHistory is not available - // fetch it from backend - if (savedSearchHistory == null) { - final response = await api.PlayersRequests.searchHistory(); + Future getPlayerData({required bool forceUpdate}) async { + if (!forceUpdate) { + isLoadingPlayerData = true; + utilities.postFrameCallback(notifyListeners); + } - if (response == null) { - searchHistory = []; + final response = await api.PlayersRequests.playerDetail( + playerId: playerId, + forceUpdate: forceUpdate, + ); - return; - } + if (response == null) { + if (!forceUpdate) isLoadingPlayerData = false; + notifyListeners(); - searchHistory = response.searchHistory; - response.searchHistory.forEach(utilities.Database.saveSearchHistory); - } else { - searchHistory = savedSearchHistory; + return; } - // remove searchHistory older than 7 days - searchHistory = searchHistory - .where( - (searchItem) => - DateTime.now().difference(searchItem.time) < - const Duration(days: 7), - ) - .toList(); + playerData = response.player; - // sort search history on basis of time - searchHistory.sort((a, b) => b.time.compareTo(a.time)); + final searchProvider = ref.read(search_provider.search); + await searchProvider.insertSearchHistory( + playerName: playerData!.name, + playerId: playerId, + ); - utilities.postFrameCallback(notifyListeners); + if (!forceUpdate) isLoadingPlayerData = false; + notifyListeners(); } - Future insertSearchHistory({ - required String playerName, - required String playerId, - }) async { - // remove existing searchItem - final index = searchHistory.indexWhere((_) => _.playerId == playerId); - if (index != -1) searchHistory.removeAt(index); - - final searchItem = models.SearchHistory( - playerName: playerName, + /// get the matches for this playerId + Future getPlayerMatches({bool forceUpdate = false}) async { + final response = await api.MatchRequests.playerMatches( playerId: playerId, - time: DateTime.now(), + forceUpdate: forceUpdate, ); + if (!forceUpdate) isPlayerMatchesLoading = false; - searchHistory.insert(0, searchItem); + if (response == null) return notifyListeners(); - // remove all entries from searchBox and reinsert entries - await utilities.Database.searchHistoryBox?.clear(); - searchHistory.forEach(utilities.Database.saveSearchHistory); - } + // create list of combinedMatches using a temp. map + final Map tempMatchesMap = {}; + for (final match in response.matches) { + tempMatchesMap[match.matchId] = data_classes.CombinedMatch( + match: match, + matchPlayers: [], + ); + } + for (final matchPlayer in response.matchPlayers) { + final existingCombinedMatch = tempMatchesMap[matchPlayer.matchId]; + if (existingCombinedMatch == null) continue; - Future searchByName({ - required String playerName, - required bool simpleResults, - required bool addInSearchHistory, - required void Function(String) onNotFound, - }) async { - // makes a request to api for search - // saves the searchItem in the local db + tempMatchesMap[matchPlayer.matchId] = existingCombinedMatch.copyWith( + matchPlayers: [...existingCombinedMatch.matchPlayers, matchPlayer], + ); + } - final response = await api.PlayersRequests.searchPlayers( - playerName: playerName, - simpleResults: simpleResults, - ); + combinedMatches = tempMatchesMap.values.toList(); - if (response == null) { - // return false when api call is not successful - return null; + // sort combinedMatches based on the selectedSort + if (combinedMatches != null) { + combinedMatches = data_classes.MatchSort.getSortedMatches( + combinedMatches: combinedMatches!, + sort: selectedSort, + ); } - if (response.exactMatch) { - playerData = response.playerData; - - if (addInSearchHistory && playerData != null) { - await insertSearchHistory( - playerName: playerData!.name, - playerId: playerData!.playerId, - ); - } - } else { - topSearchList = response.searchData.topSearchList; - lowerSearchList = response.searchData.lowerSearchList; - - if (topSearchList.isEmpty && lowerSearchList.isEmpty) { - onNotFound(playerName); - } - } - utilities.Analytics.logEvent( - constants.AnalyticsEvent.searchPlayer, - {"playerName": playerName}, + // get the playerStreak + playerStreak = utilities.getPlayerStreak( + combinedMatches, + playerId, ); - notifyListeners(); - - return response; - } + if (!forceUpdate) isPlayerMatchesLoading = false; - void clearSearchList() { - topSearchList = []; - lowerSearchList = []; notifyListeners(); } - Future getPlayerData({ - required String playerId, - required bool forceUpdate, - }) async { - if (!forceUpdate) { - isLoadingPlayerData = true; - utilities.postFrameCallback(notifyListeners); - } + void getCommonMatches() async { + final userPlayerId = ref.read(auth_provider.auth).userPlayer?.playerId; + if (userPlayerId == null) return; - final response = await api.PlayersRequests.playerDetail( - playerId: playerId, - forceUpdate: forceUpdate, - ); + isCommonMatchesLoading = true; + utilities.postFrameCallback(notifyListeners); + final response = await api.MatchRequests.commonMatches( + playerIds: [userPlayerId, playerId], + ); if (response == null) { - if (!forceUpdate) isLoadingPlayerData = false; + isCommonMatchesLoading = false; + commonMatches = null; notifyListeners(); return; } - playerData = response.player; + // create list of commonMatches using a temp. map + final Map tempMatchesMap = {}; + for (final match in response.matches) { + tempMatchesMap[match.matchId] = data_classes.CombinedMatch( + match: match, + matchPlayers: [], + ); + } + for (final matchPlayer in response.matchPlayers) { + final existingCombinedMatch = tempMatchesMap[matchPlayer.matchId]; + if (existingCombinedMatch == null) continue; - await insertSearchHistory( - playerName: playerData!.name, - playerId: playerId, + tempMatchesMap[matchPlayer.matchId] = existingCombinedMatch.copyWith( + matchPlayers: [...existingCombinedMatch.matchPlayers, matchPlayer], + ); + } + + isCommonMatchesLoading = false; + commonMatches = tempMatchesMap.values.toList(); + + // sort commonMatches based on date + if (commonMatches != null) { + commonMatches = data_classes.MatchSort.getSortedMatches( + combinedMatches: commonMatches!, + sort: data_classes.MatchSort.defaultSort, + ); + } + + notifyListeners(); + } + + /// Set value of sort and apply sorting + void setSort(String sort) { + if (combinedMatches == null) return; + + selectedSort = sort; + combinedMatches = data_classes.MatchSort.getSortedMatches( + combinedMatches: combinedMatches!, + sort: sort, ); - if (!forceUpdate) isLoadingPlayerData = false; notifyListeners(); } + /// Set value of filter and apply the filter + void setFilterValue( + String? filterName, + data_classes.MatchFilterValue? filterValue, + ) { + if (combinedMatches == null) return; + + selectedFilter = data_classes.SelectedMatchFilter( + name: filterName, + value: filterValue, + ); + final champions = ref.read(champions_provider.champions).champions; + + combinedMatches = selectedFilter.isValid + ? data_classes.MatchFilter.getFilteredMatches( + combinedMatches: combinedMatches!, + filter: selectedFilter, + champions: champions, + playerId: playerId, + ) + : data_classes.MatchFilter.clearFilters(combinedMatches!); + + notifyListeners(); + } + + /// Clears all applied filters and sort on combinedMatches + void clearAppliedFiltersAndSort() { + if (combinedMatches == null) return; + + combinedMatches = data_classes.MatchFilter.clearFilters(combinedMatches!); + combinedMatches = data_classes.MatchSort.clearSorting(combinedMatches!); + selectedFilter = data_classes.SelectedMatchFilter( + name: selectedFilter.name, + ); + selectedSort = data_classes.MatchSort.defaultSort; + + utilities.postFrameCallback(notifyListeners); + } + void resetPlayerStatus() { playerStatus = null; isLoadingPlayerStatus = false; @@ -214,20 +265,17 @@ class _PlayersNotifier extends ChangeNotifier { utilities.postFrameCallback(notifyListeners); } - /// Clears all user sensitive data upon logout - void clearData() { - isLoadingPlayerData = false; - isLoadingPlayerStatus = false; - playerData = null; - playerStatus = null; - playerInferred = null; - lowerSearchList = []; - topSearchList = []; - searchHistory = []; + void resetPlayerMatches({bool forceUpdate = false}) { + if (forceUpdate) return; + + isPlayerMatchesLoading = true; + combinedMatches = null; + playerStreak = null; + utilities.postFrameCallback(notifyListeners); } } /// Provider to handle players -final players = ChangeNotifierProvider<_PlayersNotifier>( - (ref) => _PlayersNotifier(ref: ref), +final players = ChangeNotifierProvider.family<_PlayersNotifier, String>( + (ref, playerId) => _PlayersNotifier(ref: ref, playerId: playerId), ); diff --git a/lib/providers/search.dart b/lib/providers/search.dart new file mode 100644 index 00000000..4690e012 --- /dev/null +++ b/lib/providers/search.dart @@ -0,0 +1,134 @@ +import "package:flutter/foundation.dart"; +import "package:flutter_riverpod/flutter_riverpod.dart"; +import "package:paladinsedge/api/index.dart" as api; +import "package:paladinsedge/constants/index.dart" as constants; +import "package:paladinsedge/models/index.dart" as models; +import "package:paladinsedge/utilities/index.dart" as utilities; + +class _SearchNotifier extends ChangeNotifier { + List lowerSearchList = []; + List topSearchList = []; + List searchHistory = []; + + // Loads the `searchHistory` data for the user from local db and + /// syncs it with server for showing in Search screen + void loadSearchHistory() async { + // gets the search history from local db + final savedSearchHistory = utilities.Database.getSearchHistory(); + + // if searchHistory is not available + // fetch it from backend + if (savedSearchHistory == null) { + final response = await api.PlayersRequests.searchHistory(); + + if (response == null) { + searchHistory = []; + + return; + } + + searchHistory = response.searchHistory; + response.searchHistory.forEach(utilities.Database.saveSearchHistory); + } else { + searchHistory = savedSearchHistory; + } + + // remove searchHistory older than 7 days + searchHistory = searchHistory + .where( + (searchItem) => + DateTime.now().difference(searchItem.time) < + const Duration(days: 7), + ) + .toList(); + + // sort search history on basis of time + searchHistory.sort((a, b) => b.time.compareTo(a.time)); + + utilities.postFrameCallback(notifyListeners); + } + + /// add the searched player in searchHistory + Future insertSearchHistory({ + required String playerName, + required String playerId, + }) async { + // remove existing searchItem + final index = searchHistory.indexWhere((_) => _.playerId == playerId); + if (index != -1) searchHistory.removeAt(index); + + final searchItem = models.SearchHistory( + playerName: playerName, + playerId: playerId, + time: DateTime.now(), + ); + + searchHistory.insert(0, searchItem); + + // remove all entries from searchBox and reinsert entries + await utilities.Database.searchHistoryBox?.clear(); + searchHistory.forEach(utilities.Database.saveSearchHistory); + } + + Future searchByName({ + required String playerName, + required bool simpleResults, + required bool addInSearchHistory, + required void Function(String) onNotFound, + }) async { + // makes a request to api for search + // saves the searchItem in the local db + + final response = await api.PlayersRequests.searchPlayers( + playerName: playerName, + simpleResults: simpleResults, + ); + + if (response == null) { + // return false when api call is not successful + return null; + } + + if (response.exactMatch) { + final playerData = response.playerData; + + if (addInSearchHistory && playerData != null) { + await insertSearchHistory( + playerName: playerData.name, + playerId: playerData.playerId, + ); + } + } else { + topSearchList = response.searchData.topSearchList; + lowerSearchList = response.searchData.lowerSearchList; + + if (topSearchList.isEmpty && lowerSearchList.isEmpty) { + onNotFound(playerName); + } + } + utilities.Analytics.logEvent( + constants.AnalyticsEvent.searchPlayer, + {"playerName": playerName}, + ); + + notifyListeners(); + + return response; + } + + void clearSearchList() { + topSearchList = []; + lowerSearchList = []; + notifyListeners(); + } + + /// Clears all user sensitive data upon logout + void clearData() { + lowerSearchList = []; + topSearchList = []; + searchHistory = []; + } +} + +/// Provider to handle baseRanks +final search = ChangeNotifierProvider((_) => _SearchNotifier()); diff --git a/lib/providers/top_matches.dart b/lib/providers/top_matches.dart new file mode 100644 index 00000000..b4ec791f --- /dev/null +++ b/lib/providers/top_matches.dart @@ -0,0 +1,38 @@ +import "package:flutter/foundation.dart"; +import "package:flutter_riverpod/flutter_riverpod.dart"; +import "package:paladinsedge/api/index.dart" as api; +import "package:paladinsedge/models/index.dart" as models; +import "package:paladinsedge/utilities/index.dart" as utilities; + +class _TopMatchesNotifier extends ChangeNotifier { + bool isLoading = true; + List? topMatches; + + /// Loads the `topMatches` data from local db and syncs it with server + Future loadTopMatches(bool forceUpdate) async { + final savedTopMatches = + forceUpdate ? null : utilities.Database.getTopMatches(); + + if (savedTopMatches != null) { + isLoading = false; + topMatches = savedTopMatches; + + return utilities.postFrameCallback(notifyListeners); + } + + final response = await api.MatchRequests.topMatches(); + if (response == null) return; + + isLoading = false; + topMatches = response.topMatches; + notifyListeners(); + + // save topMatches locally for future use + // clear topMatches first if forceUpdate + if (forceUpdate) await utilities.Database.topMatchBox?.clear(); + topMatches?.forEach(utilities.Database.saveTopMatch); + } +} + +/// Provider to handle baseRanks +final topMatches = ChangeNotifierProvider((_) => _TopMatchesNotifier()); diff --git a/lib/screens/active_match/active_match.dart b/lib/screens/active_match/active_match.dart index 71b74765..91d57043 100644 --- a/lib/screens/active_match/active_match.dart +++ b/lib/screens/active_match/active_match.dart @@ -39,18 +39,20 @@ class ActiveMatch extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final playersProvider = ref.read(providers.players); final championsProvider = ref.read(providers.champions); final userPlayer = ref.watch(providers.auth.select((_) => _.userPlayer)); + final playerStatusPlayerId = playerId ?? userPlayer?.playerId; + + final playerNotifier = providers.players(playerStatusPlayerId!); + final playerProvider = ref.read(playerNotifier); final isLoadingPlayerStatus = ref.watch( - providers.players.select((_) => _.isLoadingPlayerStatus), + playerNotifier.select((_) => _.isLoadingPlayerStatus), ); final playerStatus = ref.watch( - providers.players.select((_) => _.playerStatus), + playerNotifier.select((_) => _.playerStatus), ); // Variables - final playerStatusPlayerId = playerId ?? userPlayer?.playerId; final isUserPlayer = userPlayer?.playerId == playerStatusPlayerId; // State @@ -59,9 +61,7 @@ class ActiveMatch extends HookConsumerWidget { // Effects useEffect( () { - if (playerStatusPlayerId != null) { - playersProvider.getPlayerStatus(playerId: playerStatusPlayerId); - } + playerProvider.getPlayerStatus(); return null; }, @@ -92,14 +92,9 @@ class ActiveMatch extends HookConsumerWidget { // Methods final onRefresh = useCallback( () async { - if (playerStatusPlayerId != null) { - isRefreshing.value = true; - await playersProvider.getPlayerStatus( - playerId: playerStatusPlayerId, - forceUpdate: true, - ); - isRefreshing.value = false; - } + isRefreshing.value = true; + await playerProvider.getPlayerStatus(forceUpdate: true); + isRefreshing.value = false; }, [], ); @@ -139,7 +134,7 @@ class ActiveMatch extends HookConsumerWidget { status: playerStatus.status, isUserPlayer: isUserPlayer, ) - : const ActiveMatchList(), + : ActiveMatchList(playerId: playerStatusPlayerId), ], ), ), diff --git a/lib/screens/active_match/active_match_list.dart b/lib/screens/active_match/active_match_list.dart index 8c55ef9a..a1958010 100644 --- a/lib/screens/active_match/active_match_list.dart +++ b/lib/screens/active_match/active_match_list.dart @@ -7,13 +7,19 @@ import "package:paladinsedge/screens/active_match/active_match_player.dart"; import "package:paladinsedge/utilities/index.dart" as utilities; class ActiveMatchList extends HookConsumerWidget { - const ActiveMatchList({Key? key}) : super(key: key); + final String playerId; + + const ActiveMatchList({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final playerStatus = ref.watch( - providers.players.select((_) => _.playerStatus), + playerNotifier.select((_) => _.playerStatus), ); // Variables diff --git a/lib/screens/active_match/active_match_player.dart b/lib/screens/active_match/active_match_player.dart index 2fae4e8f..9b312078 100644 --- a/lib/screens/active_match/active_match_player.dart +++ b/lib/screens/active_match/active_match_player.dart @@ -203,7 +203,7 @@ class ActiveMatchPlayer extends HookConsumerWidget { () { if (isPrivatePlayer) return; - utilities.Navigation.navigate( + utilities.Navigation.push( context, screens.PlayerDetail.routeName, params: { diff --git a/lib/screens/app_drawer/app_drawer.dart b/lib/screens/app_drawer/app_drawer.dart index a0bfe5a3..c05518af 100644 --- a/lib/screens/app_drawer/app_drawer.dart +++ b/lib/screens/app_drawer/app_drawer.dart @@ -21,7 +21,6 @@ class AppDrawer extends HookConsumerWidget { // Providers final authProvider = ref.read(providers.auth); final appStateProvider = ref.read(providers.appState); - final playersProvider = ref.read(providers.players); final player = ref.watch(providers.auth.select((_) => _.userPlayer)); final isGuest = ref.watch(providers.auth.select((_) => _.isGuest)); final settings = ref.watch( @@ -89,7 +88,6 @@ class AppDrawer extends HookConsumerWidget { final onActiveMatchHelper = useCallback( () { if (player == null) return; - playersProvider.resetPlayerStatus(); utilities.Navigation.pop(context); utilities.Navigation.navigate( context, diff --git a/lib/screens/common_matches/common_matches.dart b/lib/screens/common_matches/common_matches.dart index 6069f0da..7d6dd744 100644 --- a/lib/screens/common_matches/common_matches.dart +++ b/lib/screens/common_matches/common_matches.dart @@ -32,18 +32,13 @@ class CommonMatches extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final matchesProvider = ref.read(providers.matches); - final userPlayerId = ref.watch( - providers.auth.select((_) => _.userPlayer?.playerId), - ); + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); final isCommonMatchesLoading = ref.watch( - providers.matches.select((_) => _.isCommonMatchesLoading), - ); - final commonMatchesPlayerId = ref.watch( - providers.matches.select((_) => _.commonMatchesPlayerId), + playerNotifier.select((_) => _.isCommonMatchesLoading), ); final commonMatches = ref.watch( - providers.matches.select((_) => _.commonMatches), + playerNotifier.select((_) => _.commonMatches), ); // Variables @@ -54,16 +49,11 @@ class CommonMatches extends HookConsumerWidget { // Effects useEffect( () { - if (userPlayerId != null && playerId != commonMatchesPlayerId) { - matchesProvider.getCommonMatches( - userPlayerId: userPlayerId, - playerId: playerId, - ); - } + playerProvider.getCommonMatches(); return; }, - [commonMatchesPlayerId, playerId], + [], ); return Scaffold( @@ -86,7 +76,7 @@ class CommonMatches extends HookConsumerWidget { ) : const Text("Common Matches"), ), - if (!hideList) const CommonMatchesHeader(), + if (!hideList) CommonMatchesHeader(playerId: playerId), hideList ? SliverList( delegate: SliverChildListDelegate.fixed( diff --git a/lib/screens/common_matches/common_matches_header.dart b/lib/screens/common_matches/common_matches_header.dart index 03171341..33ea20be 100644 --- a/lib/screens/common_matches/common_matches_header.dart +++ b/lib/screens/common_matches/common_matches_header.dart @@ -6,14 +6,20 @@ import "package:paladinsedge/providers/index.dart" as providers; import "package:paladinsedge/theme/index.dart" as theme; class CommonMatchesHeader extends HookConsumerWidget { - const CommonMatchesHeader({Key? key}) : super(key: key); + final String playerId; + + const CommonMatchesHeader({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final appStateProvider = ref.read(providers.appState); final commonMatches = ref.watch( - providers.matches.select((_) => _.commonMatches), + playerNotifier.select((_) => _.commonMatches), ); final settings = ref.watch( providers.appState.select((_) => _.settings), diff --git a/lib/screens/common_matches/common_matches_list.dart b/lib/screens/common_matches/common_matches_list.dart index 187723ed..5f45da7a 100644 --- a/lib/screens/common_matches/common_matches_list.dart +++ b/lib/screens/common_matches/common_matches_list.dart @@ -8,6 +8,7 @@ import "package:paladinsedge/utilities/index.dart" as utilities; class CommonMatchesList extends HookConsumerWidget { final String playerId; + const CommonMatchesList({ required this.playerId, Key? key, @@ -16,6 +17,7 @@ class CommonMatchesList extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final champions = ref.watch(providers.champions.select((_) => _.champions)); final showUserPlayerMatches = ref.watch( providers.appState.select((_) => _.settings.showUserPlayerMatches), @@ -24,7 +26,7 @@ class CommonMatchesList extends HookConsumerWidget { providers.auth.select((_) => _.userPlayer?.playerId), ); final commonMatches = ref.watch( - providers.matches.select((_) => _.commonMatches), + playerNotifier.select((_) => _.commonMatches), ); // Variables diff --git a/lib/screens/friends/friend_item.dart b/lib/screens/friends/friend_item.dart index 3754f1f3..7fb1de3d 100644 --- a/lib/screens/friends/friend_item.dart +++ b/lib/screens/friends/friend_item.dart @@ -98,7 +98,7 @@ class FriendItem extends HookConsumerWidget { final onPressFriendName = useCallback( () { - utilities.Navigation.navigate( + utilities.Navigation.push( context, screens.PlayerDetail.routeName, params: { diff --git a/lib/screens/friends/friends.dart b/lib/screens/friends/friends.dart index cc4845ea..620786ce 100644 --- a/lib/screens/friends/friends.dart +++ b/lib/screens/friends/friends.dart @@ -37,12 +37,15 @@ class Friends extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { // Providers final friendsProvider = ref.read(providers.friends); - final userPlayerId = - ref.watch(providers.auth.select((_) => _.userPlayer?.playerId)); - final isLoadingFriends = - ref.watch(providers.friends.select((_) => _.isLoadingFriends)); - final fetchedAllFriends = - ref.watch(providers.friends.select((_) => _.fetchedAllFriends)); + final userPlayerId = ref.watch( + providers.auth.select((_) => _.userPlayer?.playerId), + ); + final isLoadingFriends = ref.watch( + providers.friends.select((_) => _.isLoadingFriends), + ); + final fetchedAllFriends = ref.watch( + providers.friends.select((_) => _.fetchedAllFriends), + ); // Variables final isOtherPlayer = @@ -85,11 +88,13 @@ class Friends extends HookConsumerWidget { edgeOffset: utilities.getTopEdgeOffset(context), child: CustomScrollView( slivers: [ - FriendsAppBar( - isOtherPlayer: isOtherPlayer, - onRefresh: onRefresh, - isRefreshing: isRefreshing.value, - ), + if (playerId != null) + FriendsAppBar( + isOtherPlayer: isOtherPlayer, + onRefresh: onRefresh, + isRefreshing: isRefreshing.value, + playerId: playerId, + ), isLoadingFriends ? SliverList( delegate: SliverChildListDelegate.fixed( diff --git a/lib/screens/friends/friends_app_bar.dart b/lib/screens/friends/friends_app_bar.dart index 1e307070..8d833eec 100644 --- a/lib/screens/friends/friends_app_bar.dart +++ b/lib/screens/friends/friends_app_bar.dart @@ -8,24 +8,30 @@ class FriendsAppBar extends ConsumerWidget { final bool isOtherPlayer; final RefreshCallback onRefresh; final bool isRefreshing; + final String playerId; const FriendsAppBar({ required this.isOtherPlayer, required this.onRefresh, required this.isRefreshing, + required this.playerId, Key? key, }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final friends = ref.watch(providers.friends.select((_) => _.friends)); - final otherPlayerFriends = - ref.watch(providers.friends.select((_) => _.otherPlayerFriends)); - final isLoadingFriends = - ref.watch(providers.friends.select((_) => _.isLoadingFriends)); - final otherPlayer = - ref.watch(providers.players.select((_) => _.playerData)); + final otherPlayerFriends = ref.watch( + providers.friends.select((_) => _.otherPlayerFriends), + ); + final isLoadingFriends = ref.watch( + providers.friends.select((_) => _.isLoadingFriends), + ); + final otherPlayer = ref.watch( + playerNotifier.select((_) => _.playerData), + ); // Variables final data = isOtherPlayer ? otherPlayerFriends : friends; diff --git a/lib/screens/global_chat/global_chat.dart b/lib/screens/global_chat/global_chat.dart index 92298cd3..8d9da681 100644 --- a/lib/screens/global_chat/global_chat.dart +++ b/lib/screens/global_chat/global_chat.dart @@ -46,7 +46,7 @@ class GlobalChat extends HookConsumerWidget { // Methods final onAvatarTap = useCallback( (types.User author) { - utilities.Navigation.navigate( + utilities.Navigation.push( context, screens.PlayerDetail.routeName, params: { diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index dd4197c1..bdbcae44 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -17,7 +17,7 @@ class Home extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { // Providers final queueProvider = ref.read(providers.queue); - final matchesProvider = ref.read(providers.matches); + final topMatchesProvider = ref.read(providers.topMatches); final friendsProvider = ref.read(providers.friends); final favouriteFriends = ref.watch( providers.auth.select((_) => _.user?.favouriteFriends), @@ -31,7 +31,7 @@ class Home extends HookConsumerWidget { useEffect( () { queueProvider.getQueueTimeline(false); - matchesProvider.loadTopMatches(false); + topMatchesProvider.loadTopMatches(false); return; }, @@ -44,7 +44,7 @@ class Home extends HookConsumerWidget { isRefreshing.value = true; await Future.wait([ queueProvider.getQueueTimeline(true), - matchesProvider.loadTopMatches(true), + topMatchesProvider.loadTopMatches(true), if (favouriteFriends != null) friendsProvider.getFavouriteFriends(true), ]); diff --git a/lib/screens/home/home_top_matches.dart b/lib/screens/home/home_top_matches.dart index 0eff9afa..d0632af7 100644 --- a/lib/screens/home/home_top_matches.dart +++ b/lib/screens/home/home_top_matches.dart @@ -10,18 +10,18 @@ class HomeTopMatches extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final isTopMatchesLoading = ref.watch( - providers.matches.select((_) => _.isTopMatchesLoading), + final isLoading = ref.watch( + providers.topMatches.select((_) => _.isLoading), ); final topMatches = ref.watch( - providers.matches.select((_) => _.topMatches), + providers.topMatches.select((_) => _.topMatches), ); // Variables const itemHeight = 70.0; final textTheme = Theme.of(context).textTheme; - return isTopMatchesLoading + return isLoading ? const widgets.LoadingIndicator( lineWidth: 2, size: 28, diff --git a/lib/screens/leaderboard/leaderboard_player.dart b/lib/screens/leaderboard/leaderboard_player.dart index dc489446..582d48c0 100644 --- a/lib/screens/leaderboard/leaderboard_player.dart +++ b/lib/screens/leaderboard/leaderboard_player.dart @@ -30,7 +30,7 @@ class LeaderboardPlayer extends HookWidget { // Methods final onPressLeaderboardPlayer = useCallback( () { - utilities.Navigation.navigate( + utilities.Navigation.push( context, screens.PlayerDetail.routeName, params: { diff --git a/lib/screens/loadouts/loadouts.dart b/lib/screens/loadouts/loadouts.dart index 259f46dd..0c3f3a3f 100644 --- a/lib/screens/loadouts/loadouts.dart +++ b/lib/screens/loadouts/loadouts.dart @@ -35,18 +35,19 @@ class Loadouts extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final loadoutProvider = ref.read(providers.loadout); final championsProvider = ref.read(providers.champions); - final playersProvider = ref.read(providers.players); + final playerProvider = ref.read(playerNotifier); final userPlayerId = ref.read(providers.auth).userPlayer?.playerId; final champions = ref.read(providers.champions).champions; - final player = ref.watch(providers.players.select((_) => _.playerData)); + final player = ref.watch(playerNotifier.select((_) => _.playerData)); final loadouts = ref.watch(providers.loadout.select((_) => _.loadouts)); final isGettingLoadouts = ref.watch( providers.loadout.select((_) => _.isGettingLoadouts), ); final isLoadingPlayerData = ref.watch( - providers.players.select((_) => _.isLoadingPlayerData), + playerNotifier.select((_) => _.isLoadingPlayerData), ); final isLoadingCombinedChampions = ref.watch( providers.champions.select((_) => _.isLoadingCombinedChampions), @@ -93,12 +94,7 @@ class Loadouts extends HookConsumerWidget { () { // check if player exists, // if not, then get player - if (player == null) { - playersProvider.getPlayerData( - playerId: playerId, - forceUpdate: false, - ); - } + if (player == null) playerProvider.getPlayerData(forceUpdate: false); return; }, diff --git a/lib/screens/match_detail/match_detail.dart b/lib/screens/match_detail/match_detail.dart index e10738a9..e1950f3d 100644 --- a/lib/screens/match_detail/match_detail.dart +++ b/lib/screens/match_detail/match_detail.dart @@ -52,10 +52,11 @@ class MatchDetail extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final matchNotifier = providers.matches(matchId); final savedMatches = isSavedMatch ? ref.read(providers.auth).savedMatches : null; final matchDetails = !isSavedMatch - ? ref.watch(providers.matches.select((_) => _.matchDetails)) + ? ref.watch(matchNotifier.select((_) => _.matchDetails)) : null; // Hooks diff --git a/lib/screens/match_detail/match_detail_list.dart b/lib/screens/match_detail/match_detail_list.dart index c2196464..96f26dc6 100644 --- a/lib/screens/match_detail/match_detail_list.dart +++ b/lib/screens/match_detail/match_detail_list.dart @@ -24,10 +24,11 @@ class MatchDetailList extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - // Providers - final matchesProvider = !isSavedMatch ? ref.read(providers.matches) : null; + // ProvidersĀ Ģ° + final matchNotifier = providers.matches(matchId); + final matchProvider = !isSavedMatch ? ref.read(matchNotifier) : null; final isMatchDetailsLoading = !isSavedMatch - ? ref.watch(providers.matches.select((_) => _.isMatchDetailsLoading)) + ? ref.watch(matchNotifier.select((_) => _.isMatchDetailsLoading)) : false; final champions = ref.watch(providers.champions.select((_) => _.champions)); @@ -52,11 +53,11 @@ class MatchDetailList extends HookConsumerWidget { // Effects useEffect( () { - if (matchesProvider == null) return null; + if (matchProvider == null) return null; // call matchDetail api - matchesProvider.getMatchDetails(matchId); + matchProvider.getMatchDetails(); - return matchesProvider.resetMatchDetails; + return matchProvider.resetMatchDetails; }, [], ); diff --git a/lib/screens/match_detail/match_detail_player_card.dart b/lib/screens/match_detail/match_detail_player_card.dart index 5bf619de..ea85bfb2 100644 --- a/lib/screens/match_detail/match_detail_player_card.dart +++ b/lib/screens/match_detail/match_detail_player_card.dart @@ -265,7 +265,7 @@ class MatchDetailPlayerCard extends HookConsumerWidget { final onPressPlayer = useCallback( () { if (isPrivatePlayer) return null; - utilities.Navigation.navigate( + utilities.Navigation.push( context, screens.PlayerDetail.routeName, params: { diff --git a/lib/screens/player_champions/player_champions.dart b/lib/screens/player_champions/player_champions.dart index a72053d9..c690f768 100644 --- a/lib/screens/player_champions/player_champions.dart +++ b/lib/screens/player_champions/player_champions.dart @@ -30,8 +30,9 @@ class PlayerChampions extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final playersProvider = ref.read(providers.players); - final player = ref.watch(providers.players.select((_) => _.playerData)); + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); + final player = ref.watch(playerNotifier.select((_) => _.playerData)); final playerChampions = ref.watch( providers.champions.select((_) => _.playerChampions), ); @@ -50,12 +51,7 @@ class PlayerChampions extends HookConsumerWidget { useEffect( () { // if player is null, get it from server - if (player == null) { - playersProvider.getPlayerData( - playerId: playerId, - forceUpdate: false, - ); - } + if (player == null) playerProvider.getPlayerData(forceUpdate: false); return; }, diff --git a/lib/screens/player_detail/player_detail.dart b/lib/screens/player_detail/player_detail.dart index 2db130ad..6715198f 100644 --- a/lib/screens/player_detail/player_detail.dart +++ b/lib/screens/player_detail/player_detail.dart @@ -31,33 +31,29 @@ class PlayerDetail extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final matchesProvider = ref.read(providers.matches); - final playersProvider = ref.read(providers.players); + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); final championsProvider = ref.read(providers.champions); - final player = ref.watch(providers.players.select((_) => _.playerData)); + final player = ref.watch(playerNotifier.select((_) => _.playerData)); final isLoadingPlayerData = ref.watch( - providers.players.select((_) => _.isLoadingPlayerData), + playerNotifier.select((_) => _.isLoadingPlayerData), ); final playerStatus = ref.watch( - providers.players.select((_) => _.playerStatus), - ); - final combinedMatchesPlayerId = ref.watch( - providers.matches.select((_) => _.combinedMatchesPlayerId), + playerNotifier.select((_) => _.playerStatus), ); final playerChampionsPlayerId = ref.watch( providers.champions.select((_) => _.playerChampionsPlayerId), ); final playerInferred = ref.watch( - providers.players.select((_) => _.playerInferred), + providers.players(playerId).select((_) => _.playerInferred), ); final playerStreak = ref.watch( - providers.matches.select((_) => _.playerStreak), + playerNotifier.select((_) => _.playerStreak), ); // Variables final isSamePlayer = player?.playerId == playerId; final isSamePlayerStatus = playerStatus?.playerId == playerId; - final isSamePlayerMatches = combinedMatchesPlayerId == playerId; final isSamePlayerChampions = playerChampionsPlayerId == playerId; final isSamePlayerInferred = playerInferred?.playerId == playerId; @@ -67,30 +63,22 @@ class PlayerDetail extends HookConsumerWidget { // Methods final getPlayerDetails = useCallback( ({bool forceUpdate = false}) async { - matchesProvider.clearAppliedFiltersAndSort(); - if (!isSamePlayerMatches || forceUpdate) { - matchesProvider.resetPlayerMatches(forceUpdate: forceUpdate); - } + playerProvider.clearAppliedFiltersAndSort(); + playerProvider.resetPlayerMatches(forceUpdate: forceUpdate); await Future.wait([ if (!isSamePlayer || forceUpdate) - playersProvider.getPlayerData( - playerId: playerId, - forceUpdate: forceUpdate, - ), + playerProvider.getPlayerData(forceUpdate: forceUpdate), if (!isSamePlayerStatus || forceUpdate) - playersProvider.getPlayerStatus( - playerId: playerId, - onlyStatus: true, + playerProvider.getPlayerStatus( forceUpdate: forceUpdate, + onlyStatus: true, ), ]); await Future.wait([ - if (!isSamePlayerMatches || forceUpdate) - matchesProvider.getPlayerMatches( - playerId: playerId, - forceUpdate: forceUpdate, - ), + playerProvider.getPlayerMatches( + forceUpdate: forceUpdate, + ), if (!isSamePlayerChampions || forceUpdate) championsProvider.getPlayerChampions( playerId: playerId, @@ -99,13 +87,12 @@ class PlayerDetail extends HookConsumerWidget { ]); if (!isSamePlayerInferred || forceUpdate) { - playersProvider.getPlayerInferred(playerId: playerId); + playerProvider.getPlayerInferred(); } }, [ isSamePlayer, isSamePlayerStatus, - isSamePlayerMatches, isSamePlayerChampions, playerId, ], @@ -126,7 +113,7 @@ class PlayerDetail extends HookConsumerWidget { getPlayerDetails(); // reset the player and filters data in provider when unmounting - return matchesProvider.clearAppliedFiltersAndSort; + return playerProvider.clearAppliedFiltersAndSort; }, [playerId], ); @@ -144,9 +131,9 @@ class PlayerDetail extends HookConsumerWidget { ), ), ), - const Padding( - padding: EdgeInsets.only(right: 5), - child: PlayerDetailMenu(), + Padding( + padding: const EdgeInsets.only(right: 5), + child: PlayerDetailMenu(playerId: playerId), ), ], title: isLoadingPlayerData || player == null @@ -197,10 +184,10 @@ class PlayerDetail extends HookConsumerWidget { ) : widgets.Refresh( onRefresh: onRefresh, - child: const Stack( + child: Stack( children: [ - PlayerDetailMatches(), - PlayerDetailHeader(), + PlayerDetailMatches(playerId: playerId), + PlayerDetailHeader(playerId: playerId), ], ), ), diff --git a/lib/screens/player_detail/player_detail_filter_modal.dart b/lib/screens/player_detail/player_detail_filter_modal.dart index eee6dbbc..78a907f3 100644 --- a/lib/screens/player_detail/player_detail_filter_modal.dart +++ b/lib/screens/player_detail/player_detail_filter_modal.dart @@ -6,7 +6,7 @@ import "package:paladinsedge/screens/player_detail/player_detail_sort_tab.dart"; import "package:paladinsedge/theme/index.dart" as theme; import "package:paladinsedge/utilities/index.dart" as utilities; -void showPlayerDetailFilterModal(BuildContext context) { +void showPlayerDetailFilterModal(BuildContext context, String playerId) { final screenWidth = MediaQuery.of(context).size.width; final width = utilities.responsiveCondition( context, @@ -24,13 +24,18 @@ void showPlayerDetailFilterModal(BuildContext context) { ), ), context: context, - builder: (_) => const _PlayerDetailFilterModal(), + builder: (_) => _PlayerDetailFilterModal(playerId: playerId), constraints: BoxConstraints(maxWidth: width), ); } class _PlayerDetailFilterModal extends HookWidget { - const _PlayerDetailFilterModal({Key? key}) : super(key: key); + final String playerId; + + const _PlayerDetailFilterModal({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context) { @@ -91,11 +96,11 @@ class _PlayerDetailFilterModal extends HookWidget { ], ), ), - const Expanded( + Expanded( child: TabBarView( children: [ - PlayerDetailFilterTab(), - PlayerDetailSortTab(), + PlayerDetailFilterTab(playerId: playerId), + PlayerDetailSortTab(playerId: playerId), ], ), ), diff --git a/lib/screens/player_detail/player_detail_filter_tab.dart b/lib/screens/player_detail/player_detail_filter_tab.dart index b0f90502..1cd2c8fc 100644 --- a/lib/screens/player_detail/player_detail_filter_tab.dart +++ b/lib/screens/player_detail/player_detail_filter_tab.dart @@ -8,14 +8,20 @@ import "package:paladinsedge/theme/index.dart" as theme; import "package:paladinsedge/widgets/index.dart" as widgets; class PlayerDetailFilterTab extends HookConsumerWidget { - const PlayerDetailFilterTab({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailFilterTab({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final matchesProvider = ref.read(providers.matches); + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); final selectedFilter = ref.watch( - providers.matches.select((_) => _.selectedFilter), + playerNotifier.select((_) => _.selectedFilter), ); // Variables @@ -43,7 +49,7 @@ class PlayerDetailFilterTab extends HookConsumerWidget { data_classes.MatchFilterValue filterValue, ) { if (isFilterValueSelected) { - return matchesProvider.setFilterValue(null, null); + return playerProvider.setFilterValue(null, null); } if (filterValue.type == data_classes.MatchFilterValueType.dates) { @@ -51,11 +57,11 @@ class PlayerDetailFilterTab extends HookConsumerWidget { context, filterName, filterValue, - matchesProvider.setFilterValue, + playerProvider.setFilterValue, ); } - matchesProvider.setFilterValue(filterName, filterValue); + playerProvider.setFilterValue(filterName, filterValue); }, [], ); diff --git a/lib/screens/player_detail/player_detail_header.dart b/lib/screens/player_detail/player_detail_header.dart index 6da1a5b0..c7845980 100644 --- a/lib/screens/player_detail/player_detail_header.dart +++ b/lib/screens/player_detail/player_detail_header.dart @@ -13,18 +13,21 @@ import "package:paladinsedge/utilities/index.dart" as utilities; import "package:paladinsedge/widgets/index.dart" as widgets; class PlayerDetailHeader extends HookConsumerWidget { - const PlayerDetailHeader({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailHeader({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final baseRanks = ref.watch(providers.baseRanks).baseRanks; - final player = ref.watch(providers.players.select((_) => _.playerData)); + final player = ref.watch(playerNotifier.select((_) => _.playerData)); final playerInferred = ref.watch( - providers.players.select((_) => _.playerInferred), - ); - final playerId = ref.watch( - providers.players.select((_) => _.playerData?.playerId), + playerNotifier.select((_) => _.playerInferred), ); // Variables @@ -107,7 +110,9 @@ class PlayerDetailHeader extends HookConsumerWidget { ), ], ), - const PlayerDetailStatusIndicator(), + PlayerDetailStatusIndicator( + playerId: playerId, + ), if (isSamePlayerInferred) AnimatedRotation( duration: const Duration( @@ -134,7 +139,9 @@ class PlayerDetailHeader extends HookConsumerWidget { ExpandablePanel( controller: expandedController, collapsed: const SizedBox(), - expanded: const PlayerDetailHeaderExpandablePanel(), + expanded: PlayerDetailHeaderExpandablePanel( + playerId: playerId, + ), ), ], ), diff --git a/lib/screens/player_detail/player_detail_header_expandable_panel.dart b/lib/screens/player_detail/player_detail_header_expandable_panel.dart index 6728b03a..8557ce77 100644 --- a/lib/screens/player_detail/player_detail_header_expandable_panel.dart +++ b/lib/screens/player_detail/player_detail_header_expandable_panel.dart @@ -13,16 +13,22 @@ import "package:paladinsedge/utilities/index.dart" as utilities; import "package:paladinsedge/widgets/index.dart" as widgets; class _RecentMatchesBar extends HookConsumerWidget { - const _RecentMatchesBar({Key? key}) : super(key: key); + final String playerId; + + const _RecentMatchesBar({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final combinedMatches = ref.watch( - providers.matches.select((_) => _.combinedMatches), + playerNotifier.select((_) => _.combinedMatches), ); final playerInferred = ref.watch( - providers.players.select((_) => _.playerInferred), + playerNotifier.select((_) => _.playerInferred), ); // Hooks @@ -214,7 +220,7 @@ class _RecentPartyMemberCard extends HookWidget { // Methods final onTap = useCallback( () { - utilities.Navigation.navigate( + utilities.Navigation.push( context, screens.PlayerDetail.routeName, params: { @@ -631,16 +637,22 @@ class _PlayerStatsCard extends StatelessWidget { } class PlayerDetailHeaderExpandablePanel extends HookConsumerWidget { - const PlayerDetailHeaderExpandablePanel({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailHeaderExpandablePanel({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final player = ref.watch( - providers.players.select((_) => _.playerData), + playerNotifier.select((_) => _.playerData), ); final playerInferred = ref.watch( - providers.players.select((_) => _.playerInferred), + playerNotifier.select((_) => _.playerInferred), ); final champions = ref.watch( providers.champions.select((_) => _.champions), @@ -692,7 +704,7 @@ class PlayerDetailHeaderExpandablePanel extends HookConsumerWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 20), - const _RecentMatchesBar(), + _RecentMatchesBar(playerId: playerId), const SizedBox(height: 20), Text( "MORE PLAYER INFO", diff --git a/lib/screens/player_detail/player_detail_match_card.dart b/lib/screens/player_detail/player_detail_match_card.dart index 3dd65ac9..9626b95b 100644 --- a/lib/screens/player_detail/player_detail_match_card.dart +++ b/lib/screens/player_detail/player_detail_match_card.dart @@ -86,7 +86,7 @@ class PlayerDetailMatchCard extends HookConsumerWidget { if (isSavedMatch) routeName = screens.MatchDetail.savedMatchRouteName; if (isCommonMatch) routeName = screens.MatchDetail.commonMatchRouteName; - utilities.Navigation.navigate( + utilities.Navigation.push( context, routeName, params: { diff --git a/lib/screens/player_detail/player_detail_matches.dart b/lib/screens/player_detail/player_detail_matches.dart index fed66e8b..32c3a365 100644 --- a/lib/screens/player_detail/player_detail_matches.dart +++ b/lib/screens/player_detail/player_detail_matches.dart @@ -8,19 +8,22 @@ import "package:paladinsedge/utilities/index.dart" as utilities; import "package:paladinsedge/widgets/index.dart" as widgets; class PlayerDetailMatches extends HookConsumerWidget { - const PlayerDetailMatches({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailMatches({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers + final playerNotifier = providers.players(playerId); final isPlayerMatchesLoading = ref.watch( - providers.matches.select((_) => _.isPlayerMatchesLoading), - ); - final combinedMatchesPlayerId = ref.watch( - providers.matches.select((_) => _.combinedMatchesPlayerId), + playerNotifier.select((_) => _.isPlayerMatchesLoading), ); final combinedMatches = ref.watch( - providers.matches.select((_) => _.combinedMatches), + playerNotifier.select((_) => _.combinedMatches), ); final champions = ref.read(providers.champions).champions; @@ -77,9 +80,7 @@ class PlayerDetailMatches extends HookConsumerWidget { final combinedMatch = filteredCombinedMatches.elementAt(index); final match = combinedMatch.match; final matchPlayer = combinedMatch.matchPlayers.firstOrNullWhere( - (_) => - _.matchId == match.matchId && - _.playerId == combinedMatchesPlayerId, + (_) => _.matchId == match.matchId && _.playerId == playerId, ); final champion = champions.firstOrNullWhere( (_) => _.championId == matchPlayer?.championId, diff --git a/lib/screens/player_detail/player_detail_menu.dart b/lib/screens/player_detail/player_detail_menu.dart index f6f058d1..10c602e7 100644 --- a/lib/screens/player_detail/player_detail_menu.dart +++ b/lib/screens/player_detail/player_detail_menu.dart @@ -13,24 +13,29 @@ import "package:paladinsedge/utilities/index.dart" as utilities; import "package:paladinsedge/widgets/index.dart" as widgets; class PlayerDetailMenu extends HookConsumerWidget { - const PlayerDetailMenu({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailMenu({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final playersProvider = ref.read(providers.players); - final matchesProvider = ref.read(providers.matches); + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); final userPlayer = ref.watch(providers.auth.select((_) => _.userPlayer)); final selectedFilter = ref.watch( - providers.matches.select((_) => _.selectedFilter), + playerNotifier.select((_) => _.selectedFilter), ); final selectedSort = ref.watch( - providers.matches.select((_) => _.selectedSort), + playerNotifier.select((_) => _.selectedSort), ); - final player = ref.watch(providers.players.select((_) => _.playerData)); + final player = ref.watch(playerNotifier.select((_) => _.playerData)); final isGuest = ref.watch(providers.auth.select((_) => _.isGuest)); final playerStatus = ref.watch( - providers.players.select((_) => _.playerStatus), + playerNotifier.select((_) => _.playerStatus), ); // Variables @@ -57,7 +62,7 @@ class PlayerDetailMenu extends HookConsumerWidget { utilities.Analytics.logEvent( constants.AnalyticsEvent.otherPlayerActiveMatch, ); - playersProvider.resetPlayerStatus(); + playerProvider.resetPlayerStatus(); utilities.Navigation.pop(context); utilities.Navigation.navigate( context, @@ -112,7 +117,7 @@ class PlayerDetailMenu extends HookConsumerWidget { constants.AnalyticsEvent.playerMatchesFilterSort, ); utilities.Navigation.pop(context); - showPlayerDetailFilterModal(context); + showPlayerDetailFilterModal(context, playerId); }, [], ); @@ -149,7 +154,7 @@ class PlayerDetailMenu extends HookConsumerWidget { final onClear = useCallback( () { - matchesProvider.clearAppliedFiltersAndSort(); + playerProvider.clearAppliedFiltersAndSort(); utilities.Navigation.pop(context); }, [], diff --git a/lib/screens/player_detail/player_detail_sort_tab.dart b/lib/screens/player_detail/player_detail_sort_tab.dart index d56c2edb..89797072 100644 --- a/lib/screens/player_detail/player_detail_sort_tab.dart +++ b/lib/screens/player_detail/player_detail_sort_tab.dart @@ -7,14 +7,20 @@ import "package:paladinsedge/theme/index.dart" as theme; import "package:paladinsedge/widgets/index.dart" as widgets; class PlayerDetailSortTab extends HookConsumerWidget { - const PlayerDetailSortTab({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailSortTab({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final matchesProvider = ref.read(providers.matches); + final playerNotifier = providers.players(playerId); + final playerProvider = ref.read(playerNotifier); final selectedSort = ref.watch( - providers.matches.select((_) => _.selectedSort), + playerNotifier.select((_) => _.selectedSort), ); // Variables @@ -40,7 +46,7 @@ class PlayerDetailSortTab extends HookConsumerWidget { final isSortSelected = selectedSort == sort; return widgets.InteractiveCard( - onTap: () => matchesProvider.setSort(sort), + onTap: () => playerProvider.setSort(sort), elevation: isSortSelected ? 2 : 7, margin: const EdgeInsets.all(10), padding: const EdgeInsets.all(10), diff --git a/lib/screens/player_detail/player_detail_status_indicator.dart b/lib/screens/player_detail/player_detail_status_indicator.dart index 60958151..3f9e3286 100644 --- a/lib/screens/player_detail/player_detail_status_indicator.dart +++ b/lib/screens/player_detail/player_detail_status_indicator.dart @@ -6,16 +6,24 @@ import "package:paladinsedge/providers/index.dart" as providers; import "package:paladinsedge/widgets/index.dart" as widgets; class PlayerDetailStatusIndicator extends HookConsumerWidget { - const PlayerDetailStatusIndicator({Key? key}) : super(key: key); + final String playerId; + + const PlayerDetailStatusIndicator({ + required this.playerId, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final player = ref.watch(providers.players.select((_) => _.playerData)); - final isLoadingPlayerStatus = - ref.watch(providers.players.select((_) => _.isLoadingPlayerStatus)); - final playerStatus = - ref.watch(providers.players.select((_) => _.playerStatus)); + final playerNotifier = providers.players(playerId); + final player = ref.watch(playerNotifier.select((_) => _.playerData)); + final isLoadingPlayerStatus = ref.watch( + playerNotifier.select((_) => _.isLoadingPlayerStatus), + ); + final playerStatus = ref.watch( + playerNotifier.select((_) => _.playerStatus), + ); // Variables final status = playerStatus?.status; diff --git a/lib/screens/search/search.dart b/lib/screens/search/search.dart index 2e4cc7bd..8882e598 100644 --- a/lib/screens/search/search.dart +++ b/lib/screens/search/search.dart @@ -16,11 +16,13 @@ class Search extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final playersProvider = ref.read(providers.players); - final topSearchList = - ref.watch(providers.players.select((_) => _.topSearchList)); - final lowerSearchList = - ref.watch(providers.players.select((_) => _.lowerSearchList)); + final searchProvider = ref.read(providers.search); + final topSearchList = ref.watch( + providers.search.select((_) => _.topSearchList), + ); + final lowerSearchList = ref.watch( + providers.search.select((_) => _.lowerSearchList), + ); final isGuest = ref.watch(providers.auth.select((_) => _.isGuest)); // State @@ -70,7 +72,7 @@ class Search extends HookConsumerWidget { isLoading.value = true; - final response = await playersProvider.searchByName( + final response = await searchProvider.searchByName( playerName: playerName, simpleResults: false, addInSearchHistory: addInSearchHistory && !isGuest, @@ -90,7 +92,7 @@ class Search extends HookConsumerWidget { useEffect( () { if (!isGuest) { - playersProvider.loadSearchHistory(); + searchProvider.loadSearchHistory(); } return null; diff --git a/lib/screens/search/search_app_bar.dart b/lib/screens/search/search_app_bar.dart index 40e30933..802d563a 100644 --- a/lib/screens/search/search_app_bar.dart +++ b/lib/screens/search/search_app_bar.dart @@ -21,7 +21,7 @@ class SearchAppBar extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final playersProvider = ref.read(providers.players); + final searchProvider = ref.read(providers.search); final appStateProvider = ref.read(providers.appState); final bottomTabIndex = ref.watch( providers.appState.select((_) => _.bottomTabIndex), @@ -62,7 +62,7 @@ class SearchAppBar extends HookConsumerWidget { // Methods final onClear = useCallback( () { - playersProvider.clearSearchList(); + searchProvider.clearSearchList(); textController.clear(); onChangeText(""); }, diff --git a/lib/screens/search/search_history.dart b/lib/screens/search/search_history.dart index 82d82d8d..21822f6c 100644 --- a/lib/screens/search/search_history.dart +++ b/lib/screens/search/search_history.dart @@ -19,7 +19,7 @@ class SearchHistory extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { // Providers final searchHistory = ref.watch( - providers.players.select((_) => _.searchHistory), + providers.search.select((_) => _.searchHistory), ); // Variables diff --git a/lib/screens/search/search_lower_list.dart b/lib/screens/search/search_lower_list.dart index 1ddbb939..e373d41c 100644 --- a/lib/screens/search/search_lower_list.dart +++ b/lib/screens/search/search_lower_list.dart @@ -10,8 +10,9 @@ class SearchLowerList extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final searchProvider = ref.watch(providers.players); - final lowerSearchList = searchProvider.lowerSearchList; + final lowerSearchList = ref.watch( + providers.search.select((_) => _.lowerSearchList), + ); final childCount = min(lowerSearchList.length, 20); return SliverPadding( diff --git a/lib/screens/search/search_top_list.dart b/lib/screens/search/search_top_list.dart index 3a052221..036d6803 100644 --- a/lib/screens/search/search_top_list.dart +++ b/lib/screens/search/search_top_list.dart @@ -8,8 +8,9 @@ class SearchTopList extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final searchProvider = ref.watch(providers.players); - final topSearchList = searchProvider.topSearchList; + final topSearchList = ref.watch( + providers.search.select((_) => _.topSearchList), + ); final childCount = topSearchList.length; return SliverPadding( diff --git a/lib/widgets/connect_player_modal.dart b/lib/widgets/connect_player_modal.dart index 0e90ab2a..da1d051e 100644 --- a/lib/widgets/connect_player_modal.dart +++ b/lib/widgets/connect_player_modal.dart @@ -91,9 +91,10 @@ class _ConnectPlayerSearch extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { // Providers - final playersProvider = ref.read(providers.players); - final lowerSearchList = - ref.watch(providers.players.select((_) => _.lowerSearchList)); + final searchProvider = ref.read(providers.search); + final lowerSearchList = ref.watch( + providers.search.select((_) => _.lowerSearchList), + ); // Variables final isLightTheme = Theme.of(context).brightness == Brightness.light; @@ -128,7 +129,7 @@ class _ConnectPlayerSearch extends HookConsumerWidget { final onClear = useCallback( () { textController.clear(); - playersProvider.clearSearchList(); + searchProvider.clearSearchList(); }, [], ); @@ -145,7 +146,7 @@ class _ConnectPlayerSearch extends HookConsumerWidget { isLoading.value = true; - await playersProvider.searchByName( + await searchProvider.searchByName( playerName: playerName, simpleResults: true, addInSearchHistory: false, @@ -216,7 +217,7 @@ class _ConnectPlayerList extends HookConsumerWidget { // Providers final authProvider = ref.read(providers.auth); final lowerSearchList = ref.watch( - providers.players.select((_) => _.lowerSearchList), + providers.search.select((_) => _.lowerSearchList), ); // Variables