Skip to content

Commit 17e2c48

Browse files
committed
refactor: Refactor SourcesFilterState
- Remove status enums - Remove cursor and error - Add country and source type filters
1 parent 7e1c268 commit 17e2c48

File tree

1 file changed

+49
-60
lines changed

1 file changed

+49
-60
lines changed
Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,65 @@
11
part of 'sources_filter_bloc.dart';
22

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
74

8-
/// Currently fetching the first page of sources.
9-
loading,
5+
enum SourceFilterDataLoadingStatus { initial, loading, success, failure }
106

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 {
298
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,
3517
});
3618

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;
5227

53-
/// Creates a copy of this state with the given fields replaced.
5428
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,
6238
}) {
6339
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,
7151
);
7252
}
7353

7454
@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+
];
7665
}

0 commit comments

Comments
 (0)