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 31491e28..1b5692c6 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 @@ -431,11 +431,15 @@ class SpaceManagementBloc for (var space in orderedSpaces) { try { if (space.uuid != null && space.uuid!.isNotEmpty) { + List tagUpdates = []; + final prevSpace = await _api.getSpace(communityUuid, space.uuid!); final List subspaceUpdates = []; final List? prevSubspaces = prevSpace?.subspaces; final List? newSubspaces = space.subspaces; + tagUpdates = processTagUpdates(prevSpace?.tags, space.tags); + if (prevSubspaces != null || newSubspaces != null) { if (prevSubspaces != null && newSubspaces != null) { 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 { // Call create if the space does not have a UUID final List tagBodyModels = space.tags != null @@ -514,7 +530,6 @@ class SpaceManagementBloc }).toList() ?? []; - final response = await _api.createSpace( communityId: communityUuid, name: space.name, @@ -596,7 +611,7 @@ class SpaceManagementBloc } } - List processTagUpdates( + List processTagUpdates( List? prevTags, List? newTags, ) { @@ -670,5 +685,4 @@ class SpaceManagementBloc return tagUpdates; } - } diff --git a/lib/pages/spaces_management/all_spaces/model/space_model.dart b/lib/pages/spaces_management/all_spaces/model/space_model.dart index c8da9d9e..6ad91dad 100644 --- a/lib/pages/spaces_management/all_spaces/model/space_model.dart +++ b/lib/pages/spaces_management/all_spaces/model/space_model.dart @@ -66,7 +66,6 @@ class SpaceModel { final instance = SpaceModel( internalId: internalId, uuid: json['uuid'] ?? '', - spaceTuyaUuid: json['spaceTuyaUuid'], name: json['spaceName'], isPrivate: json['isPrivate'] ?? false, invitationCode: json['invitationCode'], diff --git a/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart index a9bc6fb8..7699dede 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart @@ -306,7 +306,6 @@ class _CommunityStructureAreaState extends State { // Set the first space in the center or use passed position Offset centerPosition = position ?? _getCenterPosition(screenSize); - print(tags); SpaceModel newSpace = SpaceModel( name: name, icon: icon, diff --git a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart index ae4349ec..eee8a25c 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart @@ -629,7 +629,25 @@ class CreateSpaceDialogState extends State { products: products, subspaces: subspaces, 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; + } + } + } + } + } + }); + }, ); }, ) diff --git a/lib/services/space_mana_api.dart b/lib/services/space_mana_api.dart index 9e6fafba..c4877c98 100644 --- a/lib/services/space_mana_api.dart +++ b/lib/services/space_mana_api.dart @@ -156,7 +156,7 @@ class CommunitySpaceManagementApi { .replaceAll('{spaceId}', spaceId) .replaceAll('{projectId}', TempConst.projectId), expectedResponseModel: (json) { - return SpaceModel.fromJson(json); + return SpaceModel.fromJson(json['data']); }, ); return response; @@ -212,7 +212,7 @@ class CommunitySpaceManagementApi { } } - Future updateSpace({ + Future updateSpace({ required String communityId, required spaceId, required String name, @@ -232,13 +232,13 @@ class CommunitySpaceManagementApi { 'y': position.dy, 'direction': direction, 'icon': icon, - 'subspace':subspaces, - 'tags':tags, + 'subspace': subspaces, + 'tags': tags, }; if (parentId != null) { body['parentUuid'] = parentId; } - + final response = await HTTPService().put( path: ApiEndpoints.updateSpace .replaceAll('{communityId}', communityId) @@ -246,13 +246,13 @@ class CommunitySpaceManagementApi { .replaceAll('{projectId}', TempConst.projectId), body: body, expectedResponseModel: (json) { - return SpaceModel.fromJson(json['data']); + return json['success'] ?? false; }, ); return response; } catch (e) { - debugPrint('Error creating space: $e'); - return null; + debugPrint('Error updating space: $e'); + return false; } }