diff --git a/lib/pages/spaces_management/widgets/sidebar_widget.dart b/lib/pages/spaces_management/widgets/sidebar_widget.dart index 2771ff09..10f03d4a 100644 --- a/lib/pages/spaces_management/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/widgets/sidebar_widget.dart @@ -17,8 +17,7 @@ class SidebarWidget extends StatefulWidget { final Function(CommunityModel)? onCommunitySelected; final List communities; - const SidebarWidget( - {super.key, this.onCommunitySelected, required this.communities}); + const SidebarWidget({super.key, this.onCommunitySelected, required this.communities}); @override _SidebarWidgetState createState() => _SidebarWidgetState(); @@ -38,8 +37,7 @@ class _SidebarWidgetState extends State { showDialog( context: parentContext, builder: (context) => CreateCommunityDialog( - onCreateCommunity: - (String communityName, String description, String regionId) { + onCreateCommunity: (String communityName, String description, String regionId) { parentContext.read().add( CreateCommunityEvent( name: communityName, @@ -65,12 +63,11 @@ class _SidebarWidgetState extends State { return widget.communities.where((community) { final containsQueryInCommunity = community.name.toLowerCase().contains(_searchQuery.toLowerCase()); - final containsQueryInSpaces = community.spaces - .any((space) => _containsQuery(space, _searchQuery.toLowerCase())); + final containsQueryInSpaces = + community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase())); if (containsQueryInCommunity || containsQueryInSpaces) { - _selectedCommunityUuid = - community.uuid; // Set the community to expanded + _selectedCommunityUuid = community.uuid; // Set the community to expanded } return containsQueryInCommunity || containsQueryInSpaces; @@ -80,8 +77,8 @@ class _SidebarWidgetState extends State { // Helper function to determine if any space or its children match the search query bool _containsQuery(SpaceModel space, String query) { final matchesSpace = space.name.toLowerCase().contains(query); - final matchesChildren = space.children.any((child) => - _containsQuery(child, query)); // Recursive check for children + final matchesChildren = + space.children.any((child) => _containsQuery(child, query)); // Recursive check for children // If the space or any of its children match the query, expand this space if (matchesSpace || matchesChildren) { @@ -115,8 +112,7 @@ class _SidebarWidgetState extends State { width: 300, decoration: subSectionContainerDecoration, child: Column( - mainAxisSize: - MainAxisSize.min, // Ensures the Column only takes necessary height + mainAxisSize: MainAxisSize.min, // Ensures the Column only takes necessary height crossAxisAlignment: CrossAxisAlignment.start, children: [ // Communities title with the add button @@ -175,8 +171,8 @@ class _SidebarWidgetState extends State { Widget _buildCommunityTile(CommunityModel community) { bool hasChildren = community.spaces.isNotEmpty; - bool isSelectedCommunity = _selectedCommunityUuid == - community.uuid; // Check if this community is selected + bool isSelectedCommunity = + _selectedCommunityUuid == community.uuid; // Check if this community is selected return CommunityTile( title: community.name, isSelected: isSelectedCommunity, @@ -194,24 +190,28 @@ class _SidebarWidgetState extends State { _handleExpansionChange(community.uuid, expanded); }, children: hasChildren - ? community.spaces.map((space) => _buildSpaceTile(space)).toList() + ? community.spaces.map((space) => _buildSpaceTile(space, community)).toList() : null, // Render spaces within the community ); } - Widget _buildSpaceTile(SpaceModel space) { - bool isSelectedSpace = - _isSpaceOrChildSelected(space); // Check if space should be expanded + Widget _buildSpaceTile(SpaceModel space, CommunityModel community) { + bool isSelectedSpace = _isSpaceOrChildSelected(space); // Check if space should be expanded return SpaceTile( title: space.name, + isSelected: isSelectedSpace, initiallyExpanded: isSelectedSpace, onExpansionChanged: (bool expanded) { _handleExpansionChange(space.uuid ?? '', expanded); }, + onItemSelected: () => { + if (widget.onCommunitySelected != null) + { + widget.onCommunitySelected!(community) // Pass the entire community + } + }, children: space.children.isNotEmpty - ? space.children - .map((childSpace) => _buildSpaceTile(childSpace)) - .toList() + ? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList() : [], // Recursively render child spaces if available ); } diff --git a/lib/pages/spaces_management/widgets/space_tile_widget.dart b/lib/pages/spaces_management/widgets/space_tile_widget.dart index e40fc5ce..95311b9a 100644 --- a/lib/pages/spaces_management/widgets/space_tile_widget.dart +++ b/lib/pages/spaces_management/widgets/space_tile_widget.dart @@ -3,15 +3,20 @@ import 'package:syncrow_web/common/custom_expansion_tile.dart'; class SpaceTile extends StatefulWidget { final String title; + final bool isSelected; + final bool initiallyExpanded; final ValueChanged onExpansionChanged; final List? children; + final Function() onItemSelected; const SpaceTile({ super.key, required this.title, required this.initiallyExpanded, required this.onExpansionChanged, + required this.onItemSelected, + required this.isSelected, this.children, }); @@ -34,6 +39,7 @@ class _SpaceTileState extends State { isSelected: false, title: widget.title, initiallyExpanded: _isExpanded, + onItemSelected: widget.onItemSelected, onExpansionChanged: (bool expanded) { setState(() { _isExpanded = expanded;