diff --git a/lib/common/custom_expansion_tile.dart b/lib/common/custom_expansion_tile.dart index 995b5d04..f637f118 100644 --- a/lib/common/custom_expansion_tile.dart +++ b/lib/common/custom_expansion_tile.dart @@ -95,9 +95,7 @@ class CustomExpansionTileState extends State { child: Text( _capitalizeFirstLetter(widget.title), style: TextStyle( - color: _isExpanded - ? ColorsManager.blackColor - : ColorsManager.lightGrayColor, + color:ColorsManager.lightGrayColor, fontWeight: FontWeight.w400, ), ), diff --git a/lib/pages/spaces_management/widgets/sidebar_widget.dart b/lib/pages/spaces_management/widgets/sidebar_widget.dart index f12f89b3..9314b10c 100644 --- a/lib/pages/spaces_management/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/widgets/sidebar_widget.dart @@ -22,7 +22,8 @@ class SidebarWidget extends StatefulWidget { class _SidebarWidgetState extends State { String _searchQuery = ''; // Track search query - Map _expandedTiles = {}; // Track expanded state for each UUID + String? _selectedCommunityUuid; + String? _selectedSpaceUuid; @override void initState() { @@ -45,29 +46,55 @@ class _SidebarWidgetState extends State { // Function to filter communities based on the search query List _filterCommunities() { if (_searchQuery.isEmpty) { + // Reset the selected community and space UUIDs if there's no query + _selectedCommunityUuid = null; + _selectedSpaceUuid = null; return widget.communities; } - // Filter communities and their spaces based on the search query + // Filter communities and expand only those that match the query return widget.communities.where((community) { final containsQueryInCommunity = community.name.toLowerCase().contains(_searchQuery.toLowerCase()); 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(); } // Helper function to determine if any space or its children match the search query bool _containsQuery(SpaceModel space, String query) { - if (space.name.toLowerCase().contains(query)) { + final matchesSpace = space.name.toLowerCase().contains(query); + 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) { + _selectedSpaceUuid = space.uuid; + } + + return matchesSpace || matchesChildren; + } + + bool _isSpaceOrChildSelected(SpaceModel space) { + // Return true if the current space or any of its child spaces is selected + if (_selectedSpaceUuid == space.uuid) { return true; } + + // Recursively check if any child spaces match the query for (var child in space.children) { - if (_containsQuery(child, query)) { + if (_isSpaceOrChildSelected(child)) { return true; } } + return false; } @@ -139,12 +166,13 @@ class _SidebarWidgetState extends State { Widget _buildCommunityTile(CommunityModel community) { bool hasChildren = community.spaces.isNotEmpty; + bool isSelectedCommunity = _selectedCommunityUuid == community.uuid; debugPrint( 'Building CommunityTile for ${community.name}, hasChildren: $hasChildren'); return CommunityTile( title: community.name, - initiallyExpanded: false, + initiallyExpanded: isSelectedCommunity, onExpansionChanged: (String title, bool expanded) { debugPrint( 'CommunityTile onExpansionChanged called for $title, expanded: $expanded'); @@ -157,11 +185,14 @@ class _SidebarWidgetState extends State { } Widget _buildSpaceTile(SpaceModel space) { + bool isSelectedSpace = + _isSpaceOrChildSelected(space); // Check if space should be expanded + debugPrint( 'Building SpaceTile for ${space.name}, hasChildren: ${space.children.isNotEmpty}'); return SpaceTile( title: space.name, - initiallyExpanded: false, + initiallyExpanded: isSelectedSpace, onExpansionChanged: (bool expanded) { debugPrint( 'SpaceTile onExpansionChanged called for ${space.name}, expanded: $expanded');