Skip to content

Commit ddb7852

Browse files
committed
feat(headlines-feed): implement HeadlinesFilterState for filter feature
- Define HeadlinesFilterStatus enum for different fetching statuses - Create HeadlinesFilterState class to hold filter options and selections - Include properties for topics, sources, countries, and followed items - Implement copyWith method for state immutability - Add error handling for failure status
1 parent ed98b8f commit ddb7852

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
part of 'headlines_filter_bloc.dart';
2+
3+
/// Enum representing the different statuses of the filter data fetching.
4+
enum HeadlinesFilterStatus {
5+
/// Initial state, no data loaded yet.
6+
initial,
7+
8+
/// Currently loading all filter data (topics, sources, countries).
9+
loading,
10+
11+
/// Successfully loaded all filter data.
12+
success,
13+
14+
/// An error occurred while fetching filter data.
15+
failure,
16+
}
17+
18+
/// {@template headlines_filter_state}
19+
/// Represents the state for the centralized headlines filter feature.
20+
///
21+
/// This state holds all available filter options (topics, sources, countries)
22+
/// and the user's current temporary selections, along with loading/error status.
23+
/// {@endtemplate}
24+
final class HeadlinesFilterState extends Equatable {
25+
/// {@macro headlines_filter_state}
26+
const HeadlinesFilterState({
27+
this.status = HeadlinesFilterStatus.initial,
28+
this.allTopics = const [],
29+
this.allSources = const [],
30+
this.allCountries = const [],
31+
this.selectedTopics = const {},
32+
this.selectedSources = const {},
33+
this.selectedCountries = const {},
34+
this.isUsingFollowedItems = false,
35+
this.error,
36+
});
37+
38+
/// The current status of fetching filter data.
39+
final HeadlinesFilterStatus status;
40+
41+
/// All available [Topic] objects that can be used for filtering.
42+
final List<Topic> allTopics;
43+
44+
/// All available [Source] objects that can be used for filtering.
45+
final List<Source> allSources;
46+
47+
/// All available [Country] objects that can be used for filtering.
48+
final List<Country> allCountries;
49+
50+
/// The set of [Topic] objects currently selected by the user.
51+
final Set<Topic> selectedTopics;
52+
53+
/// The set of [Source] objects currently selected by the user.
54+
final Set<Source> selectedSources;
55+
56+
/// The set of [Country] objects currently selected by the user.
57+
final Set<Country> selectedCountries;
58+
59+
/// Flag indicating if the filter is currently set to "Apply my followed items".
60+
final bool isUsingFollowedItems;
61+
62+
/// An optional error object if the status is [HeadlinesFilterStatus.failure].
63+
final HttpException? error;
64+
65+
/// Creates a copy of this state with the given fields replaced.
66+
HeadlinesFilterState copyWith({
67+
HeadlinesFilterStatus? status,
68+
List<Topic>? allTopics,
69+
List<Source>? allSources,
70+
List<Country>? allCountries,
71+
Set<Topic>? selectedTopics,
72+
Set<Source>? selectedSources,
73+
Set<Country>? selectedCountries,
74+
bool? isUsingFollowedItems,
75+
HttpException? error,
76+
bool clearError = false,
77+
}) {
78+
return HeadlinesFilterState(
79+
status: status ?? this.status,
80+
allTopics: allTopics ?? this.allTopics,
81+
allSources: allSources ?? this.allSources,
82+
allCountries: allCountries ?? this.allCountries,
83+
selectedTopics: selectedTopics ?? this.selectedTopics,
84+
selectedSources: selectedSources ?? this.selectedSources,
85+
selectedCountries: selectedCountries ?? this.selectedCountries,
86+
isUsingFollowedItems: isUsingFollowedItems ?? this.isUsingFollowedItems,
87+
error: clearError ? null : error ?? this.error,
88+
);
89+
}
90+
91+
@override
92+
List<Object?> get props => [
93+
status,
94+
allTopics,
95+
allSources,
96+
allCountries,
97+
selectedTopics,
98+
selectedSources,
99+
selectedCountries,
100+
isUsingFollowedItems,
101+
error,
102+
];
103+
}

0 commit comments

Comments
 (0)