diff --git a/lib/screens/home/search/search_store.dart b/lib/screens/home/search/search_store.dart index 0e3df531..9c7a7f28 100644 --- a/lib/screens/home/search/search_store.dart +++ b/lib/screens/home/search/search_store.dart @@ -87,7 +87,6 @@ abstract class SearchStoreBase with Store { } /// Obtain the channels and categories that match the provided [query]. - /// Adds the query to search history. @action void handleQuery(String query) { if (query.isEmpty) return; @@ -95,19 +94,19 @@ abstract class SearchStoreBase with Store { // Cancel any pending debounce since we're searching immediately. _debounceTimer?.cancel(); - // Move the query to the most recent result (top of the stack). - _searchHistory.remove(query); - _searchHistory.insert(0, query); - _performSearch(query); } - /// Performs the actual search API calls. + /// Performs the actual search API calls and saves the query to history. @action void _performSearch(String query) { // Futures are now pending, so isSearching can be cleared. _isSearching = false; + // Move the query to the most recent result (top of the stack). + _searchHistory.remove(query); + _searchHistory.insert(0, query); + // Fetch the matching channels, sort it by live status, and then set it. _channelFuture = twitchApi.searchChannels(query: query).then((channels) { channels.sort((c1, c2) => c2.isLive ? 1 : -1);