mirror of
https://github.com/lichess-org/mobile.git
synced 2026-05-26 13:50:52 +00:00
feat: study search sorting (#2299)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user