Refactor recursivelyInsert method in SpacesRecursiveHelper to use named parameters. Update CommunityStructureCanvas to reflect these changes, ensuring correct space insertion under the specified parent.

This commit is contained in:
Faris Armoush
2025-07-16 16:30:38 +03:00
parent 8522c0bbc3
commit 7b5b40a03c
2 changed files with 18 additions and 12 deletions

View File

@ -43,20 +43,26 @@ abstract final class SpacesRecursiveHelper {
return nonNullSpaces; return nonNullSpaces;
} }
static List<SpaceModel> recusrivelyInsert( static List<SpaceModel> recursivelyInsert({
List<SpaceModel> spaces, required List<SpaceModel> spaces,
SpaceModel newSpace, required String parentUuid,
String parentUuid, required SpaceModel newSpace,
) { }) {
return spaces.map((space) { return spaces.map((space) {
if (space.uuid == parentUuid) { final isParentSpace = space.uuid == parentUuid;
if (isParentSpace) {
return space.copyWith( return space.copyWith(
children: [...space.children, newSpace], children: [...space.children, newSpace],
); );
} }
if (space.children.isNotEmpty) { final hasChildren = space.children.isNotEmpty;
if (hasChildren) {
return space.copyWith( return space.copyWith(
children: recusrivelyInsert(space.children, newSpace, parentUuid), children: recursivelyInsert(
spaces: space.children,
parentUuid: parentUuid,
newSpace: newSpace,
),
); );
} }
return space; return space;

View File

@ -330,10 +330,10 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
communityUuid: widget.community.uuid, communityUuid: widget.community.uuid,
parentUuid: space.uuid, parentUuid: space.uuid,
onSuccess: (updatedSpaceModel) { onSuccess: (updatedSpaceModel) {
final updatedSpaces = SpacesRecursiveHelper.recusrivelyInsert( final updatedSpaces = SpacesRecursiveHelper.recursivelyInsert(
spaces, spaces: widget.community.spaces,
updatedSpaceModel, parentUuid: space.uuid,
space.uuid, newSpace: updatedSpaceModel,
); );
context.read<CommunitiesBloc>().add( context.read<CommunitiesBloc>().add(
CommunitiesUpdateCommunity( CommunitiesUpdateCommunity(