Skip to content

Commit bf1c3ae

Browse files
committed
feat(entity_details): add country support
- Extend EntityDetailsBloc to handle Country entities - Add country-specific logic for loading entities and headlines - Implement country following functionality - Update content type checks to include countries
1 parent 29633d2 commit bf1c3ae

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

lib/entity_details/bloc/entity_details_bloc.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,33 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
8282
entityToLoad = event.entity!;
8383
contentTypeToLoad = event.entity is Topic
8484
? ContentType.topic
85-
: ContentType.source;
85+
: event.entity is Country
86+
? ContentType.country
87+
: ContentType.source;
8688
} else {
8789
contentTypeToLoad = event.contentType!;
88-
if (contentTypeToLoad == ContentType.topic) {
89-
entityToLoad = await _topicRepository.read(id: event.entityId!);
90-
} else {
91-
entityToLoad = await _sourceRepository.read(id: event.entityId!);
90+
switch (contentTypeToLoad) {
91+
case ContentType.topic:
92+
entityToLoad = await _topicRepository.read(id: event.entityId!);
93+
case ContentType.source:
94+
entityToLoad = await _sourceRepository.read(id: event.entityId!);
95+
case ContentType.country:
96+
entityToLoad = await _countryRepository.read(id: event.entityId!);
97+
default:
98+
throw const OperationFailedException(
99+
'Unsupported ContentType for EntityDetails.',
100+
);
92101
}
93102
}
94103

95104
// 2. Fetch Initial Headlines
96105
final filter = <String, dynamic>{};
97106
if (contentTypeToLoad == ContentType.topic) {
98107
filter['topic.id'] = (entityToLoad as Topic).id;
99-
} else {
108+
} else if (contentTypeToLoad == ContentType.source) {
100109
filter['source.id'] = (entityToLoad as Source).id;
110+
} else if (contentTypeToLoad == ContentType.country) {
111+
filter['eventCountry.id'] = (entityToLoad as Country).id;
101112
}
102113

103114
final headlineResponse = await _headlinesRepository.readAll(
@@ -142,6 +153,10 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
142153
isCurrentlyFollowing = preferences.followedSources.any(
143154
(s) => s.id == (entityToLoad as Source).id,
144155
);
156+
} else if (entityToLoad is Country) {
157+
isCurrentlyFollowing = preferences.followedCountries.any(
158+
(c) => c.id == (entityToLoad as Country).id,
159+
);
145160
}
146161
}
147162

0 commit comments

Comments
 (0)