Skip to content

Commit 7990c4f

Browse files
committed
refactor(filter): update HeadlinesFilterPage to use new event API
Updates `HeadlinesFilterPage` to align with the changes in the `HeadlinesFeedFiltersApplied` event. The `savedFilter` parameter has been removed from the `_applyFilter` and `_applyAndExit` methods. The responsibility for determining if a filter is 'custom' or corresponds to a saved one is now fully delegated to the `HeadlinesFeedBloc`, simplifying the UI logic.
1 parent 52c3c7c commit 7990c4f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
114114
onPressed: () {
115115
// Pop the dialog first.
116116
Navigator.of(dialogContext).pop();
117-
// Apply the filter as a "custom" one-time filter.
118-
_applyAndExit(null);
117+
// Apply the filter without saving it.
118+
_applyAndExit();
119119
},
120120
),
121121
FilledButton(
@@ -161,10 +161,10 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
161161
// Add the new filter to the global AppBloc state.
162162
context.read<AppBloc>().add(SavedFilterAdded(filter: newFilter));
163163

164-
// Apply the filter to the HeadlinesFeedBloc. The page is not
165-
// popped here; that action is deferred until after the dialog
166-
// has been successfully dismissed.
167-
_applyFilter(newFilter);
164+
// Apply the newly saved filter to the HeadlinesFeedBloc. The page
165+
// is not popped here; that action is deferred until after the
166+
// dialog has been successfully dismissed.
167+
_applyFilter();
168168
},
169169
);
170170
},
@@ -180,12 +180,9 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
180180
}
181181

182182
/// Applies the current filter selections to the feed and pops the page.
183-
///
184-
/// If a [savedFilter] is provided, it's passed to the event to ensure
185-
/// its chip is correctly selected on the feed. Otherwise, the filter is
186-
/// treated as a "custom" one.
187-
void _applyFilter(SavedFilter? savedFilter) {
183+
void _applyFilter() {
188184
final filterState = context.read<HeadlinesFilterBloc>().state;
185+
// Create a new HeadlineFilter from the current selections in the filter bloc.
189186
final newFilter = HeadlineFilter(
190187
topics: filterState.selectedTopics.toList(),
191188
sources: filterState.selectedSources.toList(),
@@ -194,16 +191,15 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
194191
context.read<HeadlinesFeedBloc>().add(
195192
HeadlinesFeedFiltersApplied(
196193
filter: newFilter,
197-
savedFilter: savedFilter,
198194
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
199195
),
200196
);
201197
}
202198

203-
void _applyAndExit(SavedFilter? savedFilter) {
199+
void _applyAndExit() {
204200
// This helper method now separates applying the filter from exiting.
205201
// It's called for the "Apply Only" flow.
206-
_applyFilter(savedFilter);
202+
_applyFilter();
207203
context.pop();
208204
}
209205

0 commit comments

Comments
 (0)