mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Merge pull request #121 from SyncrowIOT:bugfix/fix-subspace-update
fixed issue in subspace update
This commit is contained in:
@ -262,27 +262,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (communities.isEmpty) {
|
|
||||||
communities = await _api.fetchCommunities(projectUuid);
|
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
|
||||||
communities.map((community) async {
|
|
||||||
List<SpaceModel> 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(
|
emit(BlankState(
|
||||||
spaceModels: prevSpaceModels,
|
spaceModels: prevSpaceModels,
|
||||||
communities: communities,
|
communities: communities,
|
||||||
@ -540,7 +519,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
List<TagModelUpdate> tagUpdates = [];
|
List<TagModelUpdate> tagUpdates = [];
|
||||||
|
|
||||||
List<SpaceModel> matchedSpaces =
|
List<SpaceModel> matchedSpaces =
|
||||||
selectedCommunity.spaces.where((space) => space.uuid == space.uuid).toList();
|
findMatchingSpaces(selectedCommunity.spaces, space.uuid!);
|
||||||
|
|
||||||
if (matchedSpaces.isEmpty) continue;
|
if (matchedSpaces.isEmpty) continue;
|
||||||
|
|
||||||
@ -696,27 +675,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
|
|
||||||
var prevSpaceModels = await fetchSpaceModels();
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
|
|
||||||
if (communities.isEmpty) {
|
|
||||||
communities = await _api.fetchCommunities(projectUuid);
|
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
|
||||||
communities.map((community) async {
|
|
||||||
List<SpaceModel> 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(
|
emit(SpaceModelLoaded(
|
||||||
communities: communities,
|
communities: communities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
@ -799,4 +757,18 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
|
|
||||||
return tagUpdates;
|
return tagUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<SpaceModel> findMatchingSpaces(List<SpaceModel> spaces, String targetUuid) {
|
||||||
|
List<SpaceModel> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user