From 7b5b40a03cda611236defe5a4ad67ebae5ba2bab Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Wed, 16 Jul 2025 16:30:38 +0300 Subject: [PATCH] Refactor `recursivelyInsert` method in `SpacesRecursiveHelper` to use named parameters. Update `CommunityStructureCanvas` to reflect these changes, ensuring correct space insertion under the specified parent. --- .../helpers/spaces_recursive_helper.dart | 22 ++++++++++++------- .../widgets/community_structure_canvas.dart | 8 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart b/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart index c470ffc1..de5ce34f 100644 --- a/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart +++ b/lib/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart @@ -43,20 +43,26 @@ abstract final class SpacesRecursiveHelper { return nonNullSpaces; } - static List recusrivelyInsert( - List spaces, - SpaceModel newSpace, - String parentUuid, - ) { + static List recursivelyInsert({ + required List spaces, + required String parentUuid, + required SpaceModel newSpace, + }) { return spaces.map((space) { - if (space.uuid == parentUuid) { + final isParentSpace = space.uuid == parentUuid; + if (isParentSpace) { return space.copyWith( children: [...space.children, newSpace], ); } - if (space.children.isNotEmpty) { + final hasChildren = space.children.isNotEmpty; + if (hasChildren) { return space.copyWith( - children: recusrivelyInsert(space.children, newSpace, parentUuid), + children: recursivelyInsert( + spaces: space.children, + parentUuid: parentUuid, + newSpace: newSpace, + ), ); } return space; diff --git a/lib/pages/space_management_v2/main_module/widgets/community_structure_canvas.dart b/lib/pages/space_management_v2/main_module/widgets/community_structure_canvas.dart index 03efab7d..692ffc0a 100644 --- a/lib/pages/space_management_v2/main_module/widgets/community_structure_canvas.dart +++ b/lib/pages/space_management_v2/main_module/widgets/community_structure_canvas.dart @@ -330,10 +330,10 @@ class _CommunityStructureCanvasState extends State communityUuid: widget.community.uuid, parentUuid: space.uuid, onSuccess: (updatedSpaceModel) { - final updatedSpaces = SpacesRecursiveHelper.recusrivelyInsert( - spaces, - updatedSpaceModel, - space.uuid, + final updatedSpaces = SpacesRecursiveHelper.recursivelyInsert( + spaces: widget.community.spaces, + parentUuid: space.uuid, + newSpace: updatedSpaceModel, ); context.read().add( CommunitiesUpdateCommunity(