Skip to content

Commit 0936211

Browse files
committed
fix(content_management): improve country search and pagination
- Update country search logic to handle empty search terms - Refine pagination handling when fetching more countries - Remove unnecessary type casting from repository responses
1 parent e1381c4 commit 0936211

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/content_management/bloc/create_headline/create_headline_bloc.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CreateHeadlineBloc
6969

7070
final countriesResponse = await _countriesRepository.readAll(
7171
sort: [const SortOption('name', SortOrder.asc)],
72-
) as PaginatedResponse<Country>;
72+
);
7373

7474
emit(
7575
state.copyWith(
@@ -204,9 +204,10 @@ class CreateHeadlineBloc
204204
emit(state.copyWith(countrySearchTerm: event.searchTerm));
205205
try {
206206
final countriesResponse = await _countriesRepository.readAll(
207-
filter: {'name': event.searchTerm},
207+
filter:
208+
event.searchTerm.isNotEmpty ? {'name': event.searchTerm} : null,
208209
sort: [const SortOption('name', SortOrder.asc)],
209-
) as PaginatedResponse<Country>;
210+
);
210211

211212
emit(
212213
state.copyWith(
@@ -235,10 +236,14 @@ class CreateHeadlineBloc
235236

236237
try {
237238
final countriesResponse = await _countriesRepository.readAll(
238-
cursor: state.countriesCursor,
239-
filter: {'name': state.countrySearchTerm},
239+
pagination: state.countriesCursor != null
240+
? PaginationOptions(cursor: state.countriesCursor)
241+
: null,
242+
filter: state.countrySearchTerm.isNotEmpty
243+
? {'name': state.countrySearchTerm}
244+
: null,
240245
sort: [const SortOption('name', SortOrder.asc)],
241-
) as PaginatedResponse<Country>;
246+
);
242247

243248
emit(
244249
state.copyWith(

0 commit comments

Comments
 (0)