diff --git a/lib/pages/spaces_management/widgets/community_structure_widget.dart b/lib/pages/spaces_management/widgets/community_structure_widget.dart index da7f3126..c8f8b3f1 100644 --- a/lib/pages/spaces_management/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_widget.dart @@ -19,8 +19,9 @@ import 'package:syncrow_web/utils/constants/assets.dart'; class CommunityStructureArea extends StatefulWidget { final CommunityModel? selectedCommunity; - final SpaceModel? selectedSpace; + SpaceModel? selectedSpace; final List? products; + final ValueChanged? onSpaceSelected; final List spaces; final List connections; @@ -31,6 +32,7 @@ class CommunityStructureArea extends StatefulWidget { this.products, required this.spaces, required this.connections, + this.onSpaceSelected, }); @override @@ -150,7 +152,7 @@ class _CommunityStructureAreaState extends State { onDoubleTap: () { _showEditSpaceDialog(visibleSpaces[index]); }, - onTap: (){ + onTap: () { _selectSpace(visibleSpaces[index]); }, icon: visibleSpaces[index].icon ?? '', @@ -559,8 +561,13 @@ class _CommunityStructureAreaState extends State { ..scale(1.2); } - void _selectSpace(SpaceModel space){ - print(space.name); - } + void _selectSpace(SpaceModel space) { + setState(() { + widget.selectedSpace = space; + }); + if (widget.onSpaceSelected != null) { + widget.onSpaceSelected!(space); + } + } } diff --git a/lib/pages/spaces_management/widgets/loaded_space_widget.dart b/lib/pages/spaces_management/widgets/loaded_space_widget.dart index 79a493bb..509ddac1 100644 --- a/lib/pages/spaces_management/widgets/loaded_space_widget.dart +++ b/lib/pages/spaces_management/widgets/loaded_space_widget.dart @@ -37,16 +37,29 @@ class _LoadedStateViewState extends State { Row( children: [ SidebarWidget( - communities: widget.communities, - onCommunitySelected: widget.onCommunitySelected, - onSpaceSelected: widget.onSpaceSelected, - ), + communities: widget.communities, + onCommunitySelected: widget.onCommunitySelected, + onSpaceSelected: widget.onSpaceSelected, + selectedSpaceUuid: widget.selectedSpace?.uuid, + onSelectedSpaceChanged: (String? spaceUuid) { + setState(() { + final selectedSpace = findSpaceByUuid(spaceUuid, widget.communities); + if (selectedSpace != null) { + widget.onSpaceSelected!(selectedSpace); + } + }); + }), CommunityStructureArea( selectedCommunity: widget.selectedCommunity, selectedSpace: widget.selectedSpace, spaces: widget.selectedCommunity?.spaces ?? [], - connections: [], + connections: const [], products: widget.products, + onSpaceSelected: (SpaceModel? space) { + setState(() { + widget.onSpaceSelected!(space); + }); + }, ), ], ), @@ -54,4 +67,13 @@ class _LoadedStateViewState extends State { ], ); } + + SpaceModel? findSpaceByUuid(String? uuid, List communities) { + for (var community in communities) { + for (var space in community.spaces) { + if (space.uuid == uuid) return space; + } + } + return null; + } } diff --git a/lib/pages/spaces_management/widgets/sidebar_widget.dart b/lib/pages/spaces_management/widgets/sidebar_widget.dart index 585b01b8..25da7d04 100644 --- a/lib/pages/spaces_management/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/widgets/sidebar_widget.dart @@ -17,9 +17,18 @@ class SidebarWidget extends StatefulWidget { final Function(CommunityModel)? onCommunitySelected; final Function(SpaceModel?)? onSpaceSelected; final List communities; + final Function(String?)? onSelectedSpaceChanged; // New callback - const SidebarWidget( - {super.key, this.onCommunitySelected, this.onSpaceSelected, required this.communities}); + final String? selectedSpaceUuid; + + const SidebarWidget({ + super.key, + this.onCommunitySelected, + this.onSpaceSelected, + this.onSelectedSpaceChanged, + required this.communities, + this.selectedSpaceUuid, + }); @override _SidebarWidgetState createState() => _SidebarWidgetState(); @@ -27,13 +36,23 @@ class SidebarWidget extends StatefulWidget { class _SidebarWidgetState extends State { String _searchQuery = ''; // Track search query - String? _selectedCommunityUuid; String? _selectedSpaceUuid; String? _selectedId; @override void initState() { super.initState(); + _selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID + } + + @override + void didUpdateWidget(covariant SidebarWidget oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid) { + setState(() { + _selectedId = widget.selectedSpaceUuid; + }); + } } void _showCreateCommunityDialog(BuildContext parentContext) { @@ -57,7 +76,6 @@ class _SidebarWidgetState extends State { List _filterCommunities() { if (_searchQuery.isEmpty) { // Reset the selected community and space UUIDs if there's no query - _selectedCommunityUuid = null; _selectedSpaceUuid = null; return widget.communities; } @@ -69,9 +87,7 @@ class _SidebarWidgetState extends State { final containsQueryInSpaces = community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase())); - if (containsQueryInCommunity || containsQueryInSpaces) { - _selectedCommunityUuid = community.uuid; // Set the community to expanded - } + return containsQueryInCommunity || containsQueryInSpaces; }).toList(); @@ -174,9 +190,7 @@ class _SidebarWidgetState extends State { Widget _buildCommunityTile(CommunityModel community) { bool hasChildren = community.spaces.isNotEmpty; - bool isSelectedCommunity = _selectedCommunityUuid == community.uuid; - // Check if this community is selected return CommunityTile( title: community.name, key: ValueKey(community.uuid), @@ -185,7 +199,6 @@ class _SidebarWidgetState extends State { onItemSelected: () { setState(() { _selectedId = community.uuid; - _selectedCommunityUuid = community.uuid; _selectedSpaceUuid = null; // Update the selected community }); @@ -218,12 +231,16 @@ class _SidebarWidgetState extends State { setState(() { _selectedId = space.uuid; _selectedSpaceUuid = space.uuid; - _selectedCommunityUuid = community.uuid; // Update selected community }); + if (widget.onSpaceSelected != null) { widget.onCommunitySelected!(community); widget.onSpaceSelected!(space); } + + if (widget.onSelectedSpaceChanged != null) { + widget.onSelectedSpaceChanged!(space.uuid); + } }, children: space.children.isNotEmpty ? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList() diff --git a/lib/pages/spaces_management/widgets/space_container_widget.dart b/lib/pages/spaces_management/widgets/space_container_widget.dart index 6bc70705..273319ce 100644 --- a/lib/pages/spaces_management/widgets/space_container_widget.dart +++ b/lib/pages/spaces_management/widgets/space_container_widget.dart @@ -22,6 +22,7 @@ class SpaceContainerWidget extends StatelessWidget { Widget build(BuildContext context) { return GestureDetector( onDoubleTap: onDoubleTap, + onTap: onTap, child: Container( width: 150, height: 60,