Skip to content

Commit 6c92d79

Browse files
committed
refactor(feed): re-add optional savedFilter to filter applied event
Re-introduces the optional `savedFilter` property to the `HeadlinesFeedFiltersApplied` event. This change is a targeted fix to resolve a race condition that occurs when a new filter is saved and immediately applied. By passing the newly created `SavedFilter` object directly, the `HeadlinesFeedBloc` can deterministically set the active filter ID without relying on its internal list of saved filters, which may not have been updated yet.
1 parent f3b4068 commit 6c92d79

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/headlines-feed/bloc/headlines_feed_event.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,35 @@ final class HeadlinesFeedRefreshRequested extends HeadlinesFeedEvent {
5252
/// Event triggered when a new set of filters, selected by the user,
5353
/// should be applied to the headlines feed.
5454
/// {@endtemplate}
55-
///
56-
/// The `activeFilterId` is now determined within the `HeadlinesFeedBloc` by
57-
/// comparing the applied filter against the list of saved filters. This makes
58-
/// passing a `savedFilter` object on this event redundant.
55+
/// The `activeFilterId` is determined within the `HeadlinesFeedBloc`.
56+
/// In most cases, this is done by comparing the applied filter against the
57+
/// list of saved filters. However, to prevent a race condition during the
58+
/// "save and apply" flow, an optional `savedFilter` can be provided to
59+
/// ensure the newly created filter is selected immediately.
5960
final class HeadlinesFeedFiltersApplied extends HeadlinesFeedEvent {
6061
/// {@macro headlines_feed_filters_applied}
6162
///
6263
/// Contains the complete [HeadlineFilter] configuration to be applied.
6364
const HeadlinesFeedFiltersApplied({
6465
required this.filter,
6566
required this.adThemeStyle,
67+
this.savedFilter,
6668
});
6769

6870
/// The [HeadlineFilter] containing the selected categories, sources,
6971
/// and/or countries.
7072
final HeadlineFilter filter;
7173

74+
/// The optional [SavedFilter] that this filter corresponds to.
75+
/// This is used exclusively during the "save and apply" flow to prevent
76+
/// a race condition and ensure the new filter's chip is selected.
77+
final SavedFilter? savedFilter;
78+
7279
/// The current ad theme style of the application.
7380
final AdThemeStyle adThemeStyle;
7481

7582
@override
76-
List<Object?> get props => [filter, adThemeStyle];
83+
List<Object?> get props => [filter, adThemeStyle, savedFilter];
7784
}
7885

7986
/// {@template headlines_feed_filters_cleared}

0 commit comments

Comments
 (0)