Merge branch 'dev' of https://github.com/SyncrowIOT/web into SP-1200

This commit is contained in:
hannathkadher
2025-04-03 10:48:56 +04:00
33 changed files with 1784 additions and 558 deletions

View File

@ -262,27 +262,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
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(
spaceModels: prevSpaceModels,
communities: communities,
@ -540,7 +519,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
List<TagModelUpdate> tagUpdates = [];
List<SpaceModel> 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<SpaceManagementEvent, SpaceManagementStat
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(
communities: communities,
products: _cachedProducts ?? [],
@ -799,4 +757,18 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
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;
}
}

View File

@ -14,6 +14,7 @@ class SpaceModel {
String? icon;
final String? spaceTuyaUuid;
String name;
String? lastThreeParents;
final bool isPrivate;
final String? invitationCode;
SpaceModel? parent;
@ -33,6 +34,7 @@ class SpaceModel {
SpaceModel({
this.uuid,
String? internalId,
this.lastThreeParents,
this.spaceTuyaUuid,
required this.icon,
required this.name,
@ -67,6 +69,7 @@ class SpaceModel {
internalId: internalId,
uuid: json['uuid'] ?? '',
name: json['spaceName'],
lastThreeParents: json['lastThreeParents'],
isPrivate: json['isPrivate'] ?? false,
invitationCode: json['invitationCode'],
subspaces: (json['subspaces'] as List<dynamic>?)
@ -125,6 +128,7 @@ class SpaceModel {
'uuid': uuid ?? '',
'spaceTuyaUuid': spaceTuyaUuid,
'name': name,
'lastThreeParents': lastThreeParents,
'isPrivate': isPrivate,
'invitationCode': invitationCode,
'parent': parent?.uuid,