diff --git a/lib/pages/spaces_management/bloc/space_management_bloc.dart b/lib/pages/spaces_management/bloc/space_management_bloc.dart index 0f5b2ad7..0df905d9 100644 --- a/lib/pages/spaces_management/bloc/space_management_bloc.dart +++ b/lib/pages/spaces_management/bloc/space_management_bloc.dart @@ -141,29 +141,25 @@ class SpaceManagementBloc extends Bloc flattenHierarchy(List spaces) { - final result = {}; // Use a Set to avoid duplicates - - // Collect all top-level spaces (those without a parent) + final result = {}; final topLevelSpaces = spaces.where((space) => space.parent == null); void visit(SpaceModel space) { if (!result.contains(space)) { - result.add(space); // Add the space + result.add(space); for (var child in spaces.where((s) => s.parent == space)) { - visit(child); // Recursively add children based on parent + visit(child); } } } - // Start with top-level spaces for (var space in topLevelSpaces) { visit(space); } - // Add any spaces that were not part of the hierarchy for (var space in spaces) { if (!result.contains(space)) { - result.add(space); // Add standalone or orphan spaces + result.add(space); } } return result.toList(); // Convert back to a list diff --git a/lib/pages/spaces_management/widgets/community_structure_widget.dart b/lib/pages/spaces_management/widgets/community_structure_widget.dart index ce5007e0..27381a61 100644 --- a/lib/pages/spaces_management/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_widget.dart @@ -38,6 +38,7 @@ class _CommunityStructureAreaState extends State { super.initState(); spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : []; connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : []; + _adjustCanvasSizeForSpaces(); } @override @@ -48,10 +49,8 @@ class _CommunityStructureAreaState extends State { setState(() { spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : []; connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : []; + _adjustCanvasSizeForSpaces(); }); - for (var space in spaces) { - print('InitState - Space Position ${space.name}: ${space.incomingConnection?.direction}'); - } } } @@ -213,6 +212,18 @@ class _CommunityStructureAreaState extends State { }); } + void _adjustCanvasSizeForSpaces() { + for (var space in spaces) { + if (space.position.dx >= canvasWidth - 200) { + canvasWidth = space.position.dx + 200; + } + + if (space.position.dy >= canvasHeight - 200) { + canvasHeight = space.position.dy + 200; + } + } + } + void _showCreateSpaceDialog(Size screenSize, {Offset? position, int? parentIndex, String? direction}) { showDialog( @@ -323,14 +334,6 @@ class _CommunityStructureAreaState extends State { List spaceList = spaces; String communityUuid = widget.selectedCommunity!.uuid; - for (var space in spaceList) { - print("Processing space: ${space.name}, UUID: ${space.uuid}"); - // Example: Log connections - print("Parent UUID: ${space.parent?.uuid}"); - print("Incoming connection: ${space.incomingConnection?.direction}"); - print("Outgoing connections: ${space.outgoingConnections.map((c) => c.direction).toList()}"); - } - // Dispatch the save event context.read().add(SaveSpacesEvent( spaces: spaceList,