diff --git a/lib/src/model/study/study_list_paginator.dart b/lib/src/model/study/study_list_paginator.dart index d698115a9..dfba57046 100644 --- a/lib/src/model/study/study_list_paginator.dart +++ b/lib/src/model/study/study_list_paginator.dart @@ -42,6 +42,6 @@ class StudyListPaginatorNotifier extends AsyncNotifier { final repo = ref.read(studyRepositoryProvider); return params.search == null ? repo.getStudies(category: params.category, order: params.order, page: nextPage) - : repo.searchStudies(query: params.search!, page: nextPage); + : repo.searchStudies(query: params.search!, order: params.order, page: nextPage); } } diff --git a/lib/src/model/study/study_repository.dart b/lib/src/model/study/study_repository.dart index 1747c7a10..d29b1a028 100644 --- a/lib/src/model/study/study_repository.dart +++ b/lib/src/model/study/study_repository.dart @@ -32,8 +32,15 @@ class StudyRepository { ); } - Future searchStudies({required String query, int page = 1}) { - return _requestStudies(path: 'search', queryParameters: {'page': page.toString(), 'q': query}); + Future searchStudies({ + required String query, + required StudyListOrder order, + int page = 1, + }) { + return _requestStudies( + path: 'search', + queryParameters: {'page': page.toString(), 'q': query, 'order': order.name}, + ); } Future _requestStudies({ diff --git a/lib/src/view/study/study_list_screen.dart b/lib/src/view/study/study_list_screen.dart index b13b3964e..fbebfcf38 100644 --- a/lib/src/view/study/study_list_screen.dart +++ b/lib/src/view/study/study_list_screen.dart @@ -127,42 +127,41 @@ class _StudyListScreenState extends ConsumerState { appBar: PlatformAppBar( title: Text(authUser != null ? context.l10n.studyMenu : context.l10n.studyAllStudies), actions: [ - if (_searchController.value.text.isEmpty) - ContextMenuIconButton( - consumeOutsideTap: true, - icon: const Icon(Icons.sort_outlined), - semanticsLabel: 'Sort studies', - actions: [ - ContextMenuAction( - icon: order == StudyListOrder.hot ? Icons.check : null, - label: context.l10n.studyHot, - onPressed: () => setState(() { - order = StudyListOrder.hot; - }), - ), - ContextMenuAction( - icon: order == StudyListOrder.newest ? Icons.check : null, - label: context.l10n.studyDateAddedNewest, - onPressed: () => setState(() { - order = StudyListOrder.newest; - }), - ), - ContextMenuAction( - icon: order == StudyListOrder.updated ? Icons.check : null, - label: context.l10n.studyRecentlyUpdated, - onPressed: () => setState(() { - order = StudyListOrder.updated; - }), - ), - ContextMenuAction( - icon: order == StudyListOrder.popular ? Icons.check : null, - label: context.l10n.studyMostPopular, - onPressed: () => setState(() { - order = StudyListOrder.popular; - }), - ), - ], - ), + ContextMenuIconButton( + consumeOutsideTap: true, + icon: const Icon(Icons.sort_outlined), + semanticsLabel: 'Sort studies', + actions: [ + ContextMenuAction( + icon: order == StudyListOrder.hot ? Icons.check : null, + label: context.l10n.studyHot, + onPressed: () => setState(() { + order = StudyListOrder.hot; + }), + ), + ContextMenuAction( + icon: order == StudyListOrder.newest ? Icons.check : null, + label: context.l10n.studyDateAddedNewest, + onPressed: () => setState(() { + order = StudyListOrder.newest; + }), + ), + ContextMenuAction( + icon: order == StudyListOrder.updated ? Icons.check : null, + label: context.l10n.studyRecentlyUpdated, + onPressed: () => setState(() { + order = StudyListOrder.updated; + }), + ), + ContextMenuAction( + icon: order == StudyListOrder.popular ? Icons.check : null, + label: context.l10n.studyMostPopular, + onPressed: () => setState(() { + order = StudyListOrder.popular; + }), + ), + ], + ), ], bottom: authUser != null ? PreferredSize( diff --git a/test/view/study/study_list_screen_test.dart b/test/view/study/study_list_screen_test.dart index 1f03e788a..6b3e304f0 100644 --- a/test/view/study/study_list_screen_test.dart +++ b/test/view/study/study_list_screen_test.dart @@ -130,7 +130,7 @@ void main() { expect(requestedUrls, [ 'https://lichess.dev/study/all/hot?page=1', - 'https://lichess.dev/study/search?page=1&q=Magnus', + 'https://lichess.dev/study/search?page=1&q=Magnus&order=hot', ]); }); });