Skip to content

Commit 9fe3eb4

Browse files
committed
feat(filter): persist source filter selections
- Initialize source filters from BLoC state - Pass filter states to HeadlinesFeedBloc
1 parent 6f5645c commit 9fe3eb4

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
5555
// Create copies of the lists to avoid modifying the BLoC state directly.
5656
_tempSelectedCategories = List.from(currentState.filter.categories ?? []);
5757
_tempSelectedSources = List.from(currentState.filter.sources ?? []);
58-
// Initialize source capsule states. These are persisted here.
59-
// For now, let's assume they start empty and are populated by SourceFilterPage's result.
60-
// Or, if HeadlineFilter could store them, we'd get them from there.
61-
// For this iteration, they start empty. SourceFilterPage will manage its own capsule
62-
// state and return it.
63-
_tempSelectedSourceCountryIsoCodes = {};
64-
_tempSelectedSourceSourceTypes = {};
58+
// Initialize source capsule states from the BLoC's current filter
59+
_tempSelectedSourceCountryIsoCodes =
60+
Set.from(currentState.filter.selectedSourceCountryIsoCodes ?? {});
61+
_tempSelectedSourceSourceTypes =
62+
Set.from(currentState.filter.selectedSourceSourceTypes ?? {});
6563
} else {
6664
_tempSelectedCategories = [];
6765
_tempSelectedSources = [];
@@ -152,11 +150,19 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
152150
categories:
153151
_tempSelectedCategories.isNotEmpty
154152
? _tempSelectedCategories
155-
: null, // Use null if empty
153+
: null,
156154
sources:
157155
_tempSelectedSources.isNotEmpty
158156
? _tempSelectedSources
159-
: null, // Use null if empty
157+
: null,
158+
selectedSourceCountryIsoCodes:
159+
_tempSelectedSourceCountryIsoCodes.isNotEmpty
160+
? _tempSelectedSourceCountryIsoCodes
161+
: null,
162+
selectedSourceSourceTypes:
163+
_tempSelectedSourceSourceTypes.isNotEmpty
164+
? _tempSelectedSourceSourceTypes
165+
: null,
160166
);
161167

162168
// Add an event to the main HeadlinesFeedBloc to apply the

0 commit comments

Comments
 (0)