feat: study search sorting (#2299)

This commit is contained in:
Tom Praschan
2025-12-01 11:51:13 +01:00
committed by GitHub
parent 9173cc13d9
commit bbd4f981b3
4 changed files with 46 additions and 40 deletions
@@ -42,6 +42,6 @@ class StudyListPaginatorNotifier extends AsyncNotifier<StudyList> {
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);
}
}
+9 -2
View File
@@ -32,8 +32,15 @@ class StudyRepository {
);
}
Future<StudyList> searchStudies({required String query, int page = 1}) {
return _requestStudies(path: 'search', queryParameters: {'page': page.toString(), 'q': query});
Future<StudyList> searchStudies({
required String query,
required StudyListOrder order,
int page = 1,
}) {
return _requestStudies(
path: 'search',
queryParameters: {'page': page.toString(), 'q': query, 'order': order.name},
);
}
Future<StudyList> _requestStudies({
+35 -36
View File
@@ -127,42 +127,41 @@ class _StudyListScreenState extends ConsumerState<StudyListScreen> {
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(
+1 -1
View File
@@ -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',
]);
});
});