Skip to content

Commit e0e790b

Browse files
committed
refactor(entity-details): simplify entity loading logic
- Remove unnecessary conditional checks for event.entity - Consolidate contentTypeToLoad assignment - Use switch statement for entity loading based on contentTypeToLoad - Remove default case for unsupported ContentType
1 parent d101471 commit e0e790b

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

lib/entity_details/bloc/entity_details_bloc.dart

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,20 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
7676
try {
7777
// 1. Determine/Fetch Entity
7878
FeedItem entityToLoad;
79-
ContentType contentTypeToLoad;
80-
81-
if (event.entity != null) {
82-
entityToLoad = event.entity!;
83-
contentTypeToLoad = event.entity is Topic
84-
? ContentType.topic
85-
: event.entity is Country
86-
? ContentType.country
87-
: ContentType.source;
88-
} else {
89-
contentTypeToLoad = event.contentType!;
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-
);
101-
}
79+
final contentTypeToLoad = event.contentType;
80+
81+
switch (contentTypeToLoad) {
82+
case ContentType.topic:
83+
entityToLoad = await _topicRepository.read(id: event.entityId);
84+
case ContentType.source:
85+
entityToLoad = await _sourceRepository.read(id: event.entityId);
86+
case ContentType.country:
87+
entityToLoad = await _countryRepository.read(id: event.entityId);
88+
// ignore: no_default_cases
89+
default:
90+
throw const OperationFailedException(
91+
'Unsupported ContentType for EntityDetails.',
92+
);
10293
}
10394

10495
// 2. Fetch Initial Headlines

0 commit comments

Comments
 (0)