|
1 | 1 | part of 'sources_filter_bloc.dart';
|
2 | 2 |
|
3 |
| -/// Enum representing the different statuses of the source filter data fetching. |
4 |
| -enum SourcesFilterStatus { |
5 |
| - /// Initial state, no data loaded yet. |
6 |
| - initial, |
| 3 | +// Import for Country, Source, SourceType will be in sources_filter_bloc.dart |
7 | 4 |
|
8 |
| - /// Currently fetching the first page of sources. |
9 |
| - loading, |
| 5 | +enum SourceFilterDataLoadingStatus { initial, loading, success, failure } |
10 | 6 |
|
11 |
| - /// Successfully loaded sources. May be loading more in the background. |
12 |
| - success, |
13 |
| - |
14 |
| - /// An error occurred while fetching sources. |
15 |
| - failure, |
16 |
| - |
17 |
| - /// Loading more sources for pagination (infinity scroll). |
18 |
| - loadingMore, |
19 |
| -} |
20 |
| - |
21 |
| -/// {@template sources_filter_state} |
22 |
| -/// Represents the state for the source filter feature. |
23 |
| -/// |
24 |
| -/// Contains the list of fetched sources, pagination information, |
25 |
| -/// loading/error status. |
26 |
| -/// {@endtemplate} |
27 |
| -final class SourcesFilterState extends Equatable { |
28 |
| - /// {@macro sources_filter_state} |
| 7 | +class SourcesFilterState extends Equatable { |
29 | 8 | const SourcesFilterState({
|
30 |
| - this.status = SourcesFilterStatus.initial, |
31 |
| - this.sources = const [], |
32 |
| - this.hasMore = true, |
33 |
| - this.cursor, |
34 |
| - this.error, |
| 9 | + this.availableCountries = const [], |
| 10 | + this.selectedCountryIsoCodes = const {}, |
| 11 | + this.availableSourceTypes = SourceType.values, |
| 12 | + this.selectedSourceTypes = const {}, |
| 13 | + this.displayableSources = const [], |
| 14 | + this.finallySelectedSourceIds = const {}, |
| 15 | + this.dataLoadingStatus = SourceFilterDataLoadingStatus.initial, |
| 16 | + this.errorMessage, |
35 | 17 | });
|
36 | 18 |
|
37 |
| - /// The current status of fetching sources. |
38 |
| - final SourcesFilterStatus status; |
39 |
| - |
40 |
| - /// The list of [Source] objects fetched so far. |
41 |
| - final List<Source> sources; |
42 |
| - |
43 |
| - /// Flag indicating if there are more sources available to fetch. |
44 |
| - final bool hasMore; |
45 |
| - |
46 |
| - /// The cursor string to fetch the next page of sources. |
47 |
| - /// This is typically the ID of the last fetched source. |
48 |
| - final String? cursor; |
49 |
| - |
50 |
| - /// An optional error object if the status is [SourcesFilterStatus.failure]. |
51 |
| - final Object? error; |
| 19 | + final List<Country> availableCountries; |
| 20 | + final Set<String> selectedCountryIsoCodes; |
| 21 | + final List<SourceType> availableSourceTypes; |
| 22 | + final Set<SourceType> selectedSourceTypes; |
| 23 | + final List<Source> displayableSources; |
| 24 | + final Set<String> finallySelectedSourceIds; |
| 25 | + final SourceFilterDataLoadingStatus dataLoadingStatus; |
| 26 | + final String? errorMessage; |
52 | 27 |
|
53 |
| - /// Creates a copy of this state with the given fields replaced. |
54 | 28 | SourcesFilterState copyWith({
|
55 |
| - SourcesFilterStatus? status, |
56 |
| - List<Source>? sources, |
57 |
| - bool? hasMore, |
58 |
| - String? cursor, |
59 |
| - Object? error, |
60 |
| - bool clearError = false, // Flag to explicitly clear the error |
61 |
| - bool clearCursor = false, // Flag to explicitly clear the cursor |
| 29 | + List<Country>? availableCountries, |
| 30 | + Set<String>? selectedCountryIsoCodes, |
| 31 | + List<SourceType>? availableSourceTypes, |
| 32 | + Set<SourceType>? selectedSourceTypes, |
| 33 | + List<Source>? displayableSources, |
| 34 | + Set<String>? finallySelectedSourceIds, |
| 35 | + SourceFilterDataLoadingStatus? dataLoadingStatus, |
| 36 | + String? errorMessage, |
| 37 | + bool clearErrorMessage = false, |
62 | 38 | }) {
|
63 | 39 | return SourcesFilterState(
|
64 |
| - status: status ?? this.status, |
65 |
| - sources: sources ?? this.sources, |
66 |
| - hasMore: hasMore ?? this.hasMore, |
67 |
| - // Allow explicitly setting cursor to null or clearing it |
68 |
| - cursor: clearCursor ? null : (cursor ?? this.cursor), |
69 |
| - // Clear error if requested, otherwise keep existing or use new one |
70 |
| - error: clearError ? null : error ?? this.error, |
| 40 | + availableCountries: availableCountries ?? this.availableCountries, |
| 41 | + selectedCountryIsoCodes: |
| 42 | + selectedCountryIsoCodes ?? this.selectedCountryIsoCodes, |
| 43 | + availableSourceTypes: availableSourceTypes ?? this.availableSourceTypes, |
| 44 | + selectedSourceTypes: selectedSourceTypes ?? this.selectedSourceTypes, |
| 45 | + displayableSources: displayableSources ?? this.displayableSources, |
| 46 | + finallySelectedSourceIds: |
| 47 | + finallySelectedSourceIds ?? this.finallySelectedSourceIds, |
| 48 | + dataLoadingStatus: dataLoadingStatus ?? this.dataLoadingStatus, |
| 49 | + errorMessage: |
| 50 | + clearErrorMessage ? null : errorMessage ?? this.errorMessage, |
71 | 51 | );
|
72 | 52 | }
|
73 | 53 |
|
74 | 54 | @override
|
75 |
| - List<Object?> get props => [status, sources, hasMore, cursor, error]; |
| 55 | + List<Object?> get props => [ |
| 56 | + availableCountries, |
| 57 | + selectedCountryIsoCodes, |
| 58 | + availableSourceTypes, |
| 59 | + selectedSourceTypes, |
| 60 | + displayableSources, |
| 61 | + finallySelectedSourceIds, |
| 62 | + dataLoadingStatus, |
| 63 | + errorMessage, |
| 64 | + ]; |
76 | 65 | }
|
0 commit comments