Skip to content

Commit 07ad1ce

Browse files
committed
feat(filter): handle no followed items
- Show snackbar message - Uncheck "Apply followed" - Clear selected filters
1 parent e7a306b commit 07ad1ce

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,55 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
129129
userId: currentUser.id,
130130
); // Assuming read by user ID
131131

132-
setState(() {
133-
_currentUserPreferences = preferences;
134-
_tempSelectedCategories = List.from(preferences.followedCategories);
135-
_tempSelectedSources = List.from(preferences.followedSources);
136-
// We don't auto-apply source country/type filters from user preferences here
137-
// as the "Apply my followed" checkbox is primarily for categories/sources.
138-
// If needed, this logic could be expanded.
139-
_isLoadingFollowedFilters = false;
140-
});
132+
// NEW: Check if followed items are empty
133+
if (preferences.followedCategories.isEmpty &&
134+
preferences.followedSources.isEmpty) {
135+
setState(() {
136+
_isLoadingFollowedFilters = false;
137+
_useFollowedFilters = false; // Uncheck the box
138+
_tempSelectedCategories = []; // Ensure lists are cleared
139+
_tempSelectedSources = [];
140+
});
141+
if (mounted) {
142+
ScaffoldMessenger.of(context)
143+
..hideCurrentSnackBar()
144+
..showSnackBar(
145+
SnackBar(
146+
content: Text(context.l10n.noFollowedItemsForFilterSnackbar),
147+
duration: const Duration(seconds: 3),
148+
),
149+
);
150+
}
151+
return; // Exit the function as no filters to apply
152+
} else {
153+
setState(() {
154+
_currentUserPreferences = preferences;
155+
_tempSelectedCategories = List.from(preferences.followedCategories);
156+
_tempSelectedSources = List.from(preferences.followedSources);
157+
// We don't auto-apply source country/type filters from user preferences here
158+
// as the "Apply my followed" checkbox is primarily for categories/sources.
159+
_isLoadingFollowedFilters = false;
160+
});
161+
}
141162
} on NotFoundException {
142163
setState(() {
143164
_currentUserPreferences =
144165
UserContentPreferences(id: currentUser.id); // Empty prefs
145166
_tempSelectedCategories = [];
146167
_tempSelectedSources = [];
147168
_isLoadingFollowedFilters = false;
148-
// Optionally, inform user they have no followed items:
149-
// _loadFollowedFiltersError = context.l10n.noFollowedItemsFound;
169+
_useFollowedFilters = false; // Uncheck as no prefs found (implies no followed)
150170
});
171+
if (mounted) {
172+
ScaffoldMessenger.of(context)
173+
..hideCurrentSnackBar()
174+
..showSnackBar(
175+
SnackBar(
176+
content: Text(context.l10n.noFollowedItemsForFilterSnackbar),
177+
duration: const Duration(seconds: 3),
178+
),
179+
);
180+
}
151181
} on HtHttpException catch (e) {
152182
setState(() {
153183
_isLoadingFollowedFilters = false;

0 commit comments

Comments
 (0)