@@ -20,12 +20,14 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
2020 required DataRepository <Headline > headlinesRepository,
2121 required DataRepository <Topic > topicRepository,
2222 required DataRepository <Source > sourceRepository,
23+ required DataRepository <Country > countryRepository,
2324 required AccountBloc accountBloc,
2425 required AppBloc appBloc,
2526 required FeedDecoratorService feedDecoratorService,
2627 }) : _headlinesRepository = headlinesRepository,
2728 _topicRepository = topicRepository,
2829 _sourceRepository = sourceRepository,
30+ _countryRepository = countryRepository,
2931 _accountBloc = accountBloc,
3032 _appBloc = appBloc,
3133 _feedDecoratorService = feedDecoratorService,
@@ -52,6 +54,7 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
5254 final DataRepository <Headline > _headlinesRepository;
5355 final DataRepository <Topic > _topicRepository;
5456 final DataRepository <Source > _sourceRepository;
57+ final DataRepository <Country > _countryRepository;
5558 final AccountBloc _accountBloc;
5659 final AppBloc _appBloc;
5760 final FeedDecoratorService _feedDecoratorService;
@@ -79,22 +82,33 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
7982 entityToLoad = event.entity! ;
8083 contentTypeToLoad = event.entity is Topic
8184 ? ContentType .topic
82- : ContentType .source;
85+ : event.entity is Country
86+ ? ContentType .country
87+ : ContentType .source;
8388 } else {
8489 contentTypeToLoad = event.contentType! ;
85- if (contentTypeToLoad == ContentType .topic) {
86- entityToLoad = await _topicRepository.read (id: event.entityId! );
87- } else {
88- 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+ );
89101 }
90102 }
91103
92104 // 2. Fetch Initial Headlines
93105 final filter = < String , dynamic > {};
94106 if (contentTypeToLoad == ContentType .topic) {
95107 filter['topic.id' ] = (entityToLoad as Topic ).id;
96- } else {
108+ } else if (contentTypeToLoad == ContentType .source) {
97109 filter['source.id' ] = (entityToLoad as Source ).id;
110+ } else if (contentTypeToLoad == ContentType .country) {
111+ filter['eventCountry.id' ] = (entityToLoad as Country ).id;
98112 }
99113
100114 final headlineResponse = await _headlinesRepository.readAll (
@@ -139,6 +153,10 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
139153 isCurrentlyFollowing = preferences.followedSources.any (
140154 (s) => s.id == (entityToLoad as Source ).id,
141155 );
156+ } else if (entityToLoad is Country ) {
157+ isCurrentlyFollowing = preferences.followedCountries.any (
158+ (c) => c.id == (entityToLoad as Country ).id,
159+ );
142160 }
143161 }
144162
@@ -179,6 +197,8 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
179197 _accountBloc.add (AccountFollowTopicToggled (topic: entity));
180198 } else if (entity is Source ) {
181199 _accountBloc.add (AccountFollowSourceToggled (source: entity));
200+ } else if (entity is Country ) {
201+ _accountBloc.add (AccountFollowCountryToggled (country: entity));
182202 }
183203 }
184204
@@ -200,6 +220,8 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
200220 filter['topic.id' ] = (state.entity! as Topic ).id;
201221 } else if (state.entity is Source ) {
202222 filter['source.id' ] = (state.entity! as Source ).id;
223+ } else if (state.entity is Country ) {
224+ filter['eventCountry.id' ] = (state.entity! as Country ).id;
203225 }
204226
205227 final headlineResponse = await _headlinesRepository.readAll (
@@ -284,6 +306,10 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
284306 isCurrentlyFollowing = preferences.followedSources.any (
285307 (s) => s.id == entity.id,
286308 );
309+ } else if (entity is Country ) {
310+ isCurrentlyFollowing = preferences.followedCountries.any (
311+ (c) => c.id == entity.id,
312+ );
287313 }
288314
289315 if (state.isFollowing != isCurrentlyFollowing) {
0 commit comments