Skip to content

Commit c6b9c08

Browse files
committed
fix(content_management): prevent multiple concurrent country load more requests
- Add countriesIsLoadingMore flag to state - Check countriesIsLoadingMore before making new load more request - Update state with countriesIsLoadingMore: true at the start of the request - Reset countriesIsLoadingMore to false in both success and error cases
1 parent a810921 commit c6b9c08

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/content_management/bloc/create_headline/create_headline_bloc.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ class CreateHeadlineBloc
230230
CreateHeadlineLoadMoreCountriesRequested event,
231231
Emitter<CreateHeadlineState> emit,
232232
) async {
233-
if (!state.countriesHasMore) return;
233+
if (!state.countriesHasMore || state.countriesIsLoadingMore) return;
234+
235+
emit(state.copyWith(countriesIsLoadingMore: true));
234236

235237
try {
236238
final countriesResponse = await _countriesRepository.readAll(
@@ -248,15 +250,23 @@ class CreateHeadlineBloc
248250
countries: List.of(state.countries)..addAll(countriesResponse.items),
249251
countriesCursor: countriesResponse.cursor,
250252
countriesHasMore: countriesResponse.hasMore,
253+
countriesIsLoadingMore: false,
251254
),
252255
);
253256
} on HttpException catch (e) {
254-
emit(state.copyWith(status: CreateHeadlineStatus.failure, exception: e));
257+
emit(
258+
state.copyWith(
259+
status: CreateHeadlineStatus.failure,
260+
exception: e,
261+
countriesIsLoadingMore: false,
262+
),
263+
);
255264
} catch (e) {
256265
emit(
257266
state.copyWith(
258267
status: CreateHeadlineStatus.failure,
259268
exception: UnknownException('An unexpected error occurred: $e'),
269+
countriesIsLoadingMore: false,
260270
),
261271
);
262272
}

0 commit comments

Comments
 (0)