Skip to content

Commit b08a259

Browse files
authored
Add filter for feeds to switch between all feeds and personal feeds. (#390)
* Add filter for feeds to switch between all feeds and personal feeds. * Change filter labels. Disable filter when not logged in.
1 parent df090d8 commit b08a259

2 files changed

Lines changed: 51 additions & 8 deletions

File tree

lib/l10n/app_en.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"filter_followers": "Followers",
3939
"filter_new": "New",
4040
"filter_read": "Read",
41+
"filter_personal": "Personal",
4142
"sort": "Sort by",
4243
"sortComments": "Sort comments",
4344
"sort_active": "Active",

lib/src/screens/explore/explore_screen.dart

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class _ExploreScreenState extends State<ExploreScreen> {
5757

5858
APIExploreSort sort = APIExploreSort.hot;
5959
ExploreFilter filter = ExploreFilter.all;
60+
FeedFilter feedFilter = FeedFilter.public;
6061

6162
late final _pagingController = AdvancedPagingController<String, dynamic, int>(
6263
logger: context.read<AppController>().logger,
@@ -111,6 +112,7 @@ class _ExploreScreenState extends State<ExploreScreen> {
111112
case ExploreType.feeds:
112113
case ExploreType.topics:
113114
final newPage = await ac.api.feed.list(
115+
mineOnly: feedFilter == FeedFilter.personal,
114116
topics: type == ExploreType.topics,
115117
includeCommunities: true,
116118
);
@@ -157,6 +159,9 @@ class _ExploreScreenState extends State<ExploreScreen> {
157159
context,
158160
type,
159161
).getOption(filter);
162+
final currentFeedFilter = feedFilterSelection(
163+
context,
164+
).getOption(feedFilter);
160165

161166
final ac = context.watch<AppController>();
162167

@@ -368,19 +373,40 @@ class _ExploreScreenState extends State<ExploreScreen> {
368373
padding: chipDropdownPadding,
369374
label: Row(
370375
mainAxisSize: MainAxisSize.min,
371-
children: [
372-
Icon(currentExploreFilter.icon, size: 20),
373-
const SizedBox(width: 4),
374-
Text(currentExploreFilter.title),
375-
const Icon(Symbols.arrow_drop_down_rounded),
376-
],
376+
children: type != ExploreType.feeds
377+
? [
378+
Icon(currentExploreFilter.icon, size: 20),
379+
const SizedBox(width: 4),
380+
Text(currentExploreFilter.title),
381+
const Icon(Symbols.arrow_drop_down_rounded),
382+
]
383+
: [
384+
Icon(currentFeedFilter.icon, size: 20),
385+
const SizedBox(width: 4),
386+
Text(currentFeedFilter.title),
387+
const Icon(Symbols.arrow_drop_down_rounded),
388+
],
377389
),
378390
onPressed:
379391
ac.serverSoftware == ServerSoftware.mbin &&
380392
type == ExploreType.all ||
381-
type == ExploreType.feeds ||
382-
type == ExploreType.topics
393+
type == ExploreType.topics ||
394+
(type == ExploreType.feeds &&
395+
(whenLoggedIn(context, false) ?? true))
383396
? null
397+
: type == ExploreType.feeds
398+
? () async {
399+
final result = await feedFilterSelection(
400+
context,
401+
).askSelection(context, feedFilter);
402+
403+
if (result != null) {
404+
setState(() {
405+
feedFilter = result;
406+
_pagingController.refresh();
407+
});
408+
}
409+
}
384410
: () async {
385411
final result = await exploreFilterSelection(
386412
context,
@@ -570,6 +596,22 @@ SelectionMenu<ExploreFilter> exploreFilterSelection(
570596
[]),
571597
]);
572598

599+
enum FeedFilter { public, personal }
600+
601+
SelectionMenu<FeedFilter> feedFilterSelection(BuildContext context) =>
602+
SelectionMenu(l(context).sort, [
603+
SelectionMenuItem(
604+
value: FeedFilter.public,
605+
title: l(context).public,
606+
icon: Symbols.newspaper_rounded,
607+
),
608+
SelectionMenuItem(
609+
value: FeedFilter.personal,
610+
title: l(context).filter_personal,
611+
icon: Symbols.home_rounded,
612+
),
613+
]);
614+
573615
SelectionMenu<APIExploreSort> exploreSortSelection(BuildContext context) {
574616
final options = [
575617
SelectionMenuItem(

0 commit comments

Comments
 (0)