diff --git a/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart b/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart index d675c680..56949a19 100644 --- a/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart +++ b/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart @@ -262,27 +262,6 @@ class SpaceManagementBloc extends Bloc updatedCommunities = await Future.wait( - communities.map((community) async { - List spaces = await _fetchSpacesForCommunity(community.uuid); - return CommunityModel( - uuid: community.uuid, - createdAt: community.createdAt, - updatedAt: community.updatedAt, - name: community.name, - description: community.description, - spaces: spaces, - region: community.region, - ); - }).toList(), - ); - - communities = updatedCommunities; - } - emit(BlankState( spaceModels: prevSpaceModels, communities: communities, @@ -540,7 +519,7 @@ class SpaceManagementBloc extends Bloc tagUpdates = []; List matchedSpaces = - selectedCommunity.spaces.where((space) => space.uuid == space.uuid).toList(); + findMatchingSpaces(selectedCommunity.spaces, space.uuid!); if (matchedSpaces.isEmpty) continue; @@ -696,27 +675,6 @@ class SpaceManagementBloc extends Bloc updatedCommunities = await Future.wait( - communities.map((community) async { - List spaces = await _fetchSpacesForCommunity(community.uuid); - return CommunityModel( - uuid: community.uuid, - createdAt: community.createdAt, - updatedAt: community.updatedAt, - name: community.name, - description: community.description, - spaces: spaces, - region: community.region, - ); - }).toList(), - ); - - communities = updatedCommunities; - } - emit(SpaceModelLoaded( communities: communities, products: _cachedProducts ?? [], @@ -799,4 +757,18 @@ class SpaceManagementBloc extends Bloc findMatchingSpaces(List spaces, String targetUuid) { + List matched = []; + + for (var space in spaces) { + if (space.uuid == targetUuid) { + matched.add(space); + } + matched + .addAll(findMatchingSpaces(space.children, targetUuid)); // Recursively search in children + } + + return matched; + } }