Skip to content

Commit 9699ad8

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 loading state in both success and error cases
1 parent c6b9c08 commit 9699ad8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/content_management/bloc/edit_headline/edit_headline_bloc.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ class EditHeadlineBloc extends Bloc<EditHeadlineEvent, EditHeadlineState> {
280280
EditHeadlineLoadMoreCountriesRequested event,
281281
Emitter<EditHeadlineState> emit,
282282
) async {
283-
if (!state.countriesHasMore) return;
283+
if (!state.countriesHasMore || state.countriesIsLoadingMore) return;
284+
285+
emit(state.copyWith(countriesIsLoadingMore: true));
284286

285287
try {
286288
final countriesResponse = await _countriesRepository.readAll(
@@ -298,15 +300,23 @@ class EditHeadlineBloc extends Bloc<EditHeadlineEvent, EditHeadlineState> {
298300
countries: List.of(state.countries)..addAll(countriesResponse.items),
299301
countriesCursor: countriesResponse.cursor,
300302
countriesHasMore: countriesResponse.hasMore,
303+
countriesIsLoadingMore: false,
301304
),
302305
);
303306
} on HttpException catch (e) {
304-
emit(state.copyWith(status: EditHeadlineStatus.failure, exception: e));
307+
emit(
308+
state.copyWith(
309+
status: EditHeadlineStatus.failure,
310+
exception: e,
311+
countriesIsLoadingMore: false,
312+
),
313+
);
305314
} catch (e) {
306315
emit(
307316
state.copyWith(
308317
status: EditHeadlineStatus.failure,
309318
exception: UnknownException('An unexpected error occurred: $e'),
319+
countriesIsLoadingMore: false,
310320
),
311321
);
312322
}

0 commit comments

Comments
 (0)