Skip to content

Commit e542b5d

Browse files
committed
refactor(filter): make reset button local and intelligently disabled
Refactors the "Reset" button on the `HeadlinesFilterPage`. The button now dispatches a `FilterSelectionsCleared` event to the local `HeadlinesFilterBloc`, clearing the selections on the page without exiting. This provides a more intuitive user experience. The button is also now intelligently disabled when there are no active selections to clear.
1 parent 4392d74 commit e542b5d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
219219
builder: (context, filterState) {
220220
final theme = Theme.of(context);
221221

222+
// Determine if the reset button should be enabled. It's enabled only
223+
// if there are active selections to clear.
224+
final isResetEnabled =
225+
filterState.selectedTopics.isNotEmpty ||
226+
filterState.selectedSources.isNotEmpty ||
227+
filterState.selectedCountries.isNotEmpty;
228+
222229
// Determine if the "Apply" button should be enabled.
223230
final isFilterEmpty =
224231
filterState.selectedTopics.isEmpty &&
@@ -259,21 +266,16 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
259266
style: theme.textTheme.titleLarge,
260267
),
261268
actions: [
262-
// Reset All Filters Button
269+
// Reset button to clear local selections on this page.
263270
IconButton(
264271
icon: const Icon(Icons.refresh),
265272
tooltip: l10n.headlinesFeedFilterResetButton,
266-
onPressed: () {
267-
// Dispatch event to clear filters in the feed bloc
268-
// and trigger a refresh to the "All" state.
269-
context.read<HeadlinesFeedBloc>().add(
270-
AllFilterSelected(
271-
adThemeStyle: AdThemeStyle.fromTheme(theme),
272-
),
273-
);
274-
// Close the filter page.
275-
context.pop();
276-
},
273+
// The button is disabled if there are no selections to clear.
274+
onPressed: isResetEnabled
275+
? () => context.read<HeadlinesFilterBloc>().add(
276+
const FilterSelectionsCleared(),
277+
)
278+
: null,
277279
),
278280
// Apply Filters Button
279281
IconButton(

0 commit comments

Comments
 (0)