Skip to content

Commit bbd4f98

Browse files
authored
feat: study search sorting (#2299)
1 parent 9173cc1 commit bbd4f98

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed

lib/src/model/study/study_list_paginator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ class StudyListPaginatorNotifier extends AsyncNotifier<StudyList> {
4242
final repo = ref.read(studyRepositoryProvider);
4343
return params.search == null
4444
? repo.getStudies(category: params.category, order: params.order, page: nextPage)
45-
: repo.searchStudies(query: params.search!, page: nextPage);
45+
: repo.searchStudies(query: params.search!, order: params.order, page: nextPage);
4646
}
4747
}

lib/src/model/study/study_repository.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ class StudyRepository {
3232
);
3333
}
3434

35-
Future<StudyList> searchStudies({required String query, int page = 1}) {
36-
return _requestStudies(path: 'search', queryParameters: {'page': page.toString(), 'q': query});
35+
Future<StudyList> searchStudies({
36+
required String query,
37+
required StudyListOrder order,
38+
int page = 1,
39+
}) {
40+
return _requestStudies(
41+
path: 'search',
42+
queryParameters: {'page': page.toString(), 'q': query, 'order': order.name},
43+
);
3744
}
3845

3946
Future<StudyList> _requestStudies({

lib/src/view/study/study_list_screen.dart

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -127,42 +127,41 @@ class _StudyListScreenState extends ConsumerState<StudyListScreen> {
127127
appBar: PlatformAppBar(
128128
title: Text(authUser != null ? context.l10n.studyMenu : context.l10n.studyAllStudies),
129129
actions: [
130-
if (_searchController.value.text.isEmpty)
131-
ContextMenuIconButton(
132-
consumeOutsideTap: true,
133-
icon: const Icon(Icons.sort_outlined),
134-
semanticsLabel: 'Sort studies',
135-
actions: [
136-
ContextMenuAction(
137-
icon: order == StudyListOrder.hot ? Icons.check : null,
138-
label: context.l10n.studyHot,
139-
onPressed: () => setState(() {
140-
order = StudyListOrder.hot;
141-
}),
142-
),
143-
ContextMenuAction(
144-
icon: order == StudyListOrder.newest ? Icons.check : null,
145-
label: context.l10n.studyDateAddedNewest,
146-
onPressed: () => setState(() {
147-
order = StudyListOrder.newest;
148-
}),
149-
),
150-
ContextMenuAction(
151-
icon: order == StudyListOrder.updated ? Icons.check : null,
152-
label: context.l10n.studyRecentlyUpdated,
153-
onPressed: () => setState(() {
154-
order = StudyListOrder.updated;
155-
}),
156-
),
157-
ContextMenuAction(
158-
icon: order == StudyListOrder.popular ? Icons.check : null,
159-
label: context.l10n.studyMostPopular,
160-
onPressed: () => setState(() {
161-
order = StudyListOrder.popular;
162-
}),
163-
),
164-
],
165-
),
130+
ContextMenuIconButton(
131+
consumeOutsideTap: true,
132+
icon: const Icon(Icons.sort_outlined),
133+
semanticsLabel: 'Sort studies',
134+
actions: [
135+
ContextMenuAction(
136+
icon: order == StudyListOrder.hot ? Icons.check : null,
137+
label: context.l10n.studyHot,
138+
onPressed: () => setState(() {
139+
order = StudyListOrder.hot;
140+
}),
141+
),
142+
ContextMenuAction(
143+
icon: order == StudyListOrder.newest ? Icons.check : null,
144+
label: context.l10n.studyDateAddedNewest,
145+
onPressed: () => setState(() {
146+
order = StudyListOrder.newest;
147+
}),
148+
),
149+
ContextMenuAction(
150+
icon: order == StudyListOrder.updated ? Icons.check : null,
151+
label: context.l10n.studyRecentlyUpdated,
152+
onPressed: () => setState(() {
153+
order = StudyListOrder.updated;
154+
}),
155+
),
156+
ContextMenuAction(
157+
icon: order == StudyListOrder.popular ? Icons.check : null,
158+
label: context.l10n.studyMostPopular,
159+
onPressed: () => setState(() {
160+
order = StudyListOrder.popular;
161+
}),
162+
),
163+
],
164+
),
166165
],
167166
bottom: authUser != null
168167
? PreferredSize(

test/view/study/study_list_screen_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void main() {
130130

131131
expect(requestedUrls, [
132132
'https://lichess.dev/study/all/hot?page=1',
133-
'https://lichess.dev/study/search?page=1&q=Magnus',
133+
'https://lichess.dev/study/search?page=1&q=Magnus&order=hot',
134134
]);
135135
});
136136
});

0 commit comments

Comments
 (0)