Skip to content

Commit f53ed5d

Browse files
committed
feat(entity_details): create entity details state
- Define states and statuses - Add copyWith method - Implement Equatable
1 parent e9b5d01 commit f53ed5d

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
part of 'entity_details_bloc.dart';
2+
3+
/// Status for the overall entity details page.
4+
enum EntityDetailsStatus {
5+
initial,
6+
loading,
7+
success,
8+
failure,
9+
}
10+
11+
/// Status for fetching headlines within the entity details page.
12+
enum EntityHeadlinesStatus {
13+
initial,
14+
loadingMore,
15+
success,
16+
failure,
17+
}
18+
19+
class EntityDetailsState extends Equatable {
20+
const EntityDetailsState({
21+
this.status = EntityDetailsStatus.initial,
22+
this.entityType,
23+
this.entity,
24+
this.isFollowing = false,
25+
this.headlines = const [],
26+
this.headlinesStatus = EntityHeadlinesStatus.initial,
27+
this.hasMoreHeadlines = true,
28+
this.headlinesCursor,
29+
this.errorMessage,
30+
});
31+
32+
final EntityDetailsStatus status;
33+
final EntityType? entityType;
34+
final dynamic entity; // Will be Category or Source
35+
final bool isFollowing;
36+
final List<Headline> headlines;
37+
final EntityHeadlinesStatus headlinesStatus;
38+
final bool hasMoreHeadlines;
39+
final String? headlinesCursor;
40+
final String? errorMessage;
41+
42+
EntityDetailsState copyWith({
43+
EntityDetailsStatus? status,
44+
EntityType? entityType,
45+
dynamic entity,
46+
bool? isFollowing,
47+
List<Headline>? headlines,
48+
EntityHeadlinesStatus? headlinesStatus,
49+
bool? hasMoreHeadlines,
50+
String? headlinesCursor,
51+
String? errorMessage,
52+
bool clearErrorMessage = false,
53+
bool clearEntity = false,
54+
bool clearHeadlinesCursor = false,
55+
}) {
56+
return EntityDetailsState(
57+
status: status ?? this.status,
58+
entityType: entityType ?? this.entityType,
59+
entity: clearEntity ? null : entity ?? this.entity,
60+
isFollowing: isFollowing ?? this.isFollowing,
61+
headlines: headlines ?? this.headlines,
62+
headlinesStatus: headlinesStatus ?? this.headlinesStatus,
63+
hasMoreHeadlines: hasMoreHeadlines ?? this.hasMoreHeadlines,
64+
headlinesCursor: clearHeadlinesCursor
65+
? null
66+
: headlinesCursor ?? this.headlinesCursor,
67+
errorMessage:
68+
clearErrorMessage ? null : errorMessage ?? this.errorMessage,
69+
);
70+
}
71+
72+
@override
73+
List<Object?> get props => [
74+
status,
75+
entityType,
76+
entity,
77+
isFollowing,
78+
headlines,
79+
headlinesStatus,
80+
hasMoreHeadlines,
81+
headlinesCursor,
82+
errorMessage,
83+
];
84+
}

0 commit comments

Comments
 (0)