This commit is contained in:
2026-07-13 01:38:13 +03:00
parent 9eda119527
commit 98c5a7a1d1
54 changed files with 860 additions and 454 deletions

View File

@@ -9,26 +9,53 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
NotificationsBloc(this._getNotificationsUsecase) : super(const NotificationsState()) {
on<NotificationsFetchRequested>(_onFetchRequested);
on<NotificationsLoadMoreRequested>(_onLoadMoreRequested);
}
Future<void> _onFetchRequested(
NotificationsFetchRequested event,
Emitter<NotificationsState> emit,
) async {
emit(state.copyWith(status: NotificationsStatus.loading));
if (event.page == 1) {
emit(state.copyWith(status: NotificationsStatus.loading));
}
try {
final notifications = await _getNotificationsUsecase();
final result = await _getNotificationsUsecase(
page: event.page,
pageSize: 100,
);
final newNotifications = event.page == 1
? result.notifications
: [...state.notifications, ...result.notifications];
emit(state.copyWith(
status: NotificationsStatus.success,
notifications: notifications,
notifications: newNotifications,
currentPage: result.pagination.currentPage,
totalPages: result.pagination.lastPage,
hasMore: result.pagination.currentPage < result.pagination.lastPage,
isLoadingMore: false,
));
} catch (e) {
dev.log('NotificationsBloc: Ошибка загрузки: $e');
emit(state.copyWith(
status: NotificationsStatus.failure,
errorMessage: e.toString(),
status: event.page == 1 ? NotificationsStatus.failure : NotificationsStatus.success,
errorMessage: event.page == 1 ? e.toString() : null,
isLoadingMore: false,
));
}
}
Future<void> _onLoadMoreRequested(
NotificationsLoadMoreRequested event,
Emitter<NotificationsState> emit,
) async {
if (!state.hasMore || state.isLoadingMore) return;
emit(state.copyWith(isLoadingMore: true));
final nextPage = state.currentPage + 1;
add(NotificationsFetchRequested(page: nextPage));
}
}