fixed update space

This commit is contained in:
hannathkadher
2025-01-29 11:14:12 +04:00
parent 073916d4ac
commit 4bae7bb9fb
5 changed files with 44 additions and 14 deletions

View File

@ -431,11 +431,15 @@ class SpaceManagementBloc
for (var space in orderedSpaces) { for (var space in orderedSpaces) {
try { try {
if (space.uuid != null && space.uuid!.isNotEmpty) { if (space.uuid != null && space.uuid!.isNotEmpty) {
List<TagModelUpdate> tagUpdates = [];
final prevSpace = await _api.getSpace(communityUuid, space.uuid!); final prevSpace = await _api.getSpace(communityUuid, space.uuid!);
final List<UpdateSubspaceTemplateModel> subspaceUpdates = []; final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces; final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
final List<SubspaceModel>? newSubspaces = space.subspaces; final List<SubspaceModel>? newSubspaces = space.subspaces;
tagUpdates = processTagUpdates(prevSpace?.tags, space.tags);
if (prevSubspaces != null || newSubspaces != null) { if (prevSubspaces != null || newSubspaces != null) {
if (prevSubspaces != null && newSubspaces != null) { if (prevSubspaces != null && newSubspaces != null) {
for (var prevSubspace in prevSubspaces) { for (var prevSubspace in prevSubspaces) {
@ -497,6 +501,18 @@ class SpaceManagementBloc
} }
} }
final response = await _api.updateSpace(
communityId: communityUuid,
spaceId: space.uuid!,
name: space.name,
parentId: space.parent?.uuid,
isPrivate: space.isPrivate,
position: space.position,
icon: space.icon,
subspaces: subspaceUpdates,
tags: tagUpdates,
direction: space.incomingConnection?.direction,
);
} else { } else {
// Call create if the space does not have a UUID // Call create if the space does not have a UUID
final List<CreateTagBodyModel> tagBodyModels = space.tags != null final List<CreateTagBodyModel> tagBodyModels = space.tags != null
@ -514,7 +530,6 @@ class SpaceManagementBloc
}).toList() ?? }).toList() ??
[]; [];
final response = await _api.createSpace( final response = await _api.createSpace(
communityId: communityUuid, communityId: communityUuid,
name: space.name, name: space.name,
@ -596,7 +611,7 @@ class SpaceManagementBloc
} }
} }
List<TagModelUpdate> processTagUpdates( List<TagModelUpdate> processTagUpdates(
List<Tag>? prevTags, List<Tag>? prevTags,
List<Tag>? newTags, List<Tag>? newTags,
) { ) {
@ -670,5 +685,4 @@ class SpaceManagementBloc
return tagUpdates; return tagUpdates;
} }
} }

View File

@ -66,7 +66,6 @@ class SpaceModel {
final instance = SpaceModel( final instance = SpaceModel(
internalId: internalId, internalId: internalId,
uuid: json['uuid'] ?? '', uuid: json['uuid'] ?? '',
spaceTuyaUuid: json['spaceTuyaUuid'],
name: json['spaceName'], name: json['spaceName'],
isPrivate: json['isPrivate'] ?? false, isPrivate: json['isPrivate'] ?? false,
invitationCode: json['invitationCode'], invitationCode: json['invitationCode'],

View File

@ -306,7 +306,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
// Set the first space in the center or use passed position // Set the first space in the center or use passed position
Offset centerPosition = Offset centerPosition =
position ?? _getCenterPosition(screenSize); position ?? _getCenterPosition(screenSize);
print(tags);
SpaceModel newSpace = SpaceModel( SpaceModel newSpace = SpaceModel(
name: name, name: name,
icon: icon, icon: icon,

View File

@ -629,7 +629,25 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
products: products, products: products,
subspaces: subspaces, subspaces: subspaces,
allTags: [], allTags: [],
onSave: (selectedSpaceTags, selectedSubspaces) {}, onSave: (selectedSpaceTags, selectedSubspaces) {
setState(() {
tags = selectedSpaceTags;
selectedSpaceModel = null;
if (selectedSubspaces != null) {
if (subspaces != null) {
for (final subspace in subspaces!) {
for (final selectedSubspace in selectedSubspaces) {
if (subspace.subspaceName ==
selectedSubspace.subspaceName) {
subspace.tags = selectedSubspace.tags;
}
}
}
}
}
});
},
); );
}, },
) )

View File

@ -156,7 +156,7 @@ class CommunitySpaceManagementApi {
.replaceAll('{spaceId}', spaceId) .replaceAll('{spaceId}', spaceId)
.replaceAll('{projectId}', TempConst.projectId), .replaceAll('{projectId}', TempConst.projectId),
expectedResponseModel: (json) { expectedResponseModel: (json) {
return SpaceModel.fromJson(json); return SpaceModel.fromJson(json['data']);
}, },
); );
return response; return response;
@ -212,7 +212,7 @@ class CommunitySpaceManagementApi {
} }
} }
Future<SpaceModel?> updateSpace({ Future<bool> updateSpace({
required String communityId, required String communityId,
required spaceId, required spaceId,
required String name, required String name,
@ -232,8 +232,8 @@ class CommunitySpaceManagementApi {
'y': position.dy, 'y': position.dy,
'direction': direction, 'direction': direction,
'icon': icon, 'icon': icon,
'subspace':subspaces, 'subspace': subspaces,
'tags':tags, 'tags': tags,
}; };
if (parentId != null) { if (parentId != null) {
body['parentUuid'] = parentId; body['parentUuid'] = parentId;
@ -246,13 +246,13 @@ class CommunitySpaceManagementApi {
.replaceAll('{projectId}', TempConst.projectId), .replaceAll('{projectId}', TempConst.projectId),
body: body, body: body,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return SpaceModel.fromJson(json['data']); return json['success'] ?? false;
}, },
); );
return response; return response;
} catch (e) { } catch (e) {
debugPrint('Error creating space: $e'); debugPrint('Error updating space: $e');
return null; return false;
} }
} }