mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
shows a loading indicator when loading.
This commit is contained in:
@ -14,7 +14,7 @@ final class DebouncedCommunitiesService implements CommunitiesService {
|
||||
final Duration debounceDuration;
|
||||
|
||||
Timer? _debounceTimer;
|
||||
Completer<CommunitiesPaginationModel>? _completer;
|
||||
late Completer<CommunitiesPaginationModel>? _completer;
|
||||
|
||||
@override
|
||||
Future<CommunitiesPaginationModel> getCommunity(
|
||||
@ -22,10 +22,6 @@ final class DebouncedCommunitiesService implements CommunitiesService {
|
||||
) async {
|
||||
_debounceTimer?.cancel();
|
||||
|
||||
if (_completer != null && !_completer!.isCompleted) {
|
||||
_completer!.completeError(Exception('Request cancelled by newer request'));
|
||||
}
|
||||
|
||||
_completer = Completer<CommunitiesPaginationModel>();
|
||||
final currentCompleter = _completer!;
|
||||
|
||||
|
@ -24,9 +24,13 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
Emitter<CommunitiesState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(state.copyWith(status: CommunitiesStatus.loading));
|
||||
emit(
|
||||
state.copyWith(status: CommunitiesStatus.loading),
|
||||
);
|
||||
|
||||
final paginationResponse = await _communitiesService.getCommunity(event.param);
|
||||
final paginationResponse = await _communitiesService.getCommunity(
|
||||
event.param,
|
||||
);
|
||||
|
||||
emit(
|
||||
CommunitiesState(
|
||||
@ -35,6 +39,7 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
hasNext: paginationResponse.hasNext,
|
||||
currentPage: paginationResponse.page,
|
||||
searchQuery: event.param.search,
|
||||
isLoadingMore: false,
|
||||
),
|
||||
);
|
||||
} on APIException catch (e) {
|
||||
@ -65,6 +70,7 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: CommunitiesStatus.success,
|
||||
communities: updatedCommunities,
|
||||
hasNext: paginationResponse.hasNext,
|
||||
currentPage: paginationResponse.page,
|
||||
@ -84,6 +90,7 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: CommunitiesStatus.failure,
|
||||
isLoadingMore: false,
|
||||
errorMessage: e.message,
|
||||
),
|
||||
@ -93,6 +100,7 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
void _onError(Object e, Emitter<CommunitiesState> emit) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: CommunitiesStatus.failure,
|
||||
isLoadingMore: false,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
|
@ -42,11 +42,9 @@ class _SpaceManagementCommunitiesTreeState
|
||||
}
|
||||
|
||||
void _onSearchChanged(String searchQuery) {
|
||||
context.read<CommunitiesBloc>().add(
|
||||
LoadCommunities(LoadCommunitiesParam(
|
||||
search: searchQuery.trim(),
|
||||
)),
|
||||
);
|
||||
context
|
||||
.read<CommunitiesBloc>()
|
||||
.add(LoadCommunities(LoadCommunitiesParam(search: searchQuery.trim())));
|
||||
}
|
||||
|
||||
void _onLoadMore() {
|
||||
@ -80,6 +78,13 @@ class _SpaceManagementCommunitiesTreeState
|
||||
CommunitiesStatus.success => _buildCommunitiesTree(context, state),
|
||||
CommunitiesStatus.failure => _buildErrorState(context, state),
|
||||
},
|
||||
Visibility(
|
||||
visible: state.isLoadingMore,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -132,7 +137,9 @@ class _SpaceManagementCommunitiesTreeState
|
||||
}
|
||||
|
||||
return Expanded(
|
||||
child: SpaceManagementSidebarCommunitiesList(
|
||||
child: Stack(
|
||||
children: [
|
||||
SpaceManagementSidebarCommunitiesList(
|
||||
communities: state.communities,
|
||||
onLoadMore: state.hasNext ? _onLoadMore : null,
|
||||
isLoadingMore: state.isLoadingMore,
|
||||
@ -141,6 +148,14 @@ class _SpaceManagementCommunitiesTreeState
|
||||
return _buildCommunityTile(context, state.communities[index]);
|
||||
},
|
||||
),
|
||||
if (state.status == CommunitiesStatus.loading &&
|
||||
state.communities.isNotEmpty)
|
||||
ColoredBox(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ class _SpaceManagementSidebarCommunitiesListState
|
||||
void _onScroll() {
|
||||
if (_scrollController.position.pixels >=
|
||||
_scrollController.position.maxScrollExtent - 100) {
|
||||
// Trigger pagination when user is close to the bottom
|
||||
if (widget.hasNext && !widget.isLoadingMore && widget.onLoadMore != null) {
|
||||
widget.onLoadMore!();
|
||||
}
|
||||
@ -67,7 +66,6 @@ class _SpaceManagementSidebarCommunitiesListState
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Calculate item count including loading indicator
|
||||
final itemCount = widget.communities.length + (widget.isLoadingMore ? 1 : 0);
|
||||
|
||||
return SingleChildScrollView(
|
||||
|
Reference in New Issue
Block a user