diff --git a/lib/pages/spaces_management/widgets/sidebar_widget.dart b/lib/pages/spaces_management/widgets/sidebar_widget.dart index 507cd703..affc3fd0 100644 --- a/lib/pages/spaces_management/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/widgets/sidebar_widget.dart @@ -42,7 +42,8 @@ class _SidebarWidgetState extends State { @override void initState() { super.initState(); - _selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID + _selectedId = widget + .selectedSpaceUuid; // Initialize with the passed selected space UUID } @override @@ -83,8 +84,8 @@ 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())); return containsQueryInCommunity || containsQueryInSpaces; }).toList(); @@ -93,8 +94,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) { @@ -128,7 +129,8 @@ 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 @@ -176,7 +178,7 @@ class _SidebarWidgetState extends State { Expanded( child: ListView( children: filteredCommunities.map((community) { - return _buildCommunityTile(community); + return _buildCommunityTile(context, community); }).toList(), ), ), @@ -185,7 +187,7 @@ class _SidebarWidgetState extends State { ); } - Widget _buildCommunityTile(CommunityModel community) { + Widget _buildCommunityTile(BuildContext context, CommunityModel community) { bool hasChildren = community.spaces.isNotEmpty; return CommunityTile( @@ -199,16 +201,17 @@ class _SidebarWidgetState extends State { _selectedSpaceUuid = null; // Update the selected community }); - if (widget.onCommunitySelected != null) { - widget.onCommunitySelected!(community); - widget.onSpaceSelected!(null); // Pass the entire community - } + context.read().add( + SelectCommunityEvent(selectedCommunity: community), + ); }, onExpansionChanged: (String title, bool expanded) { _handleExpansionChange(community.uuid, expanded); }, children: hasChildren - ? community.spaces.map((space) => _buildSpaceTile(space, community)).toList() + ? community.spaces + .map((space) => _buildSpaceTile(space, community)) + .toList() : null, // Render spaces within the community ); } @@ -230,17 +233,15 @@ class _SidebarWidgetState extends State { _selectedSpaceUuid = space.uuid; }); - if (widget.onSpaceSelected != null) { - widget.onCommunitySelected!(community); - widget.onSpaceSelected!(space); - } - - if (widget.onSelectedSpaceChanged != null) { - widget.onSelectedSpaceChanged!(space.uuid); - } + context.read().add( + SelectSpaceEvent( + selectedCommunity: community, selectedSpace: space), + ); }, children: space.children.isNotEmpty - ? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList() + ? space.children + .map((childSpace) => _buildSpaceTile(childSpace, community)) + .toList() : [], // Recursively render child spaces if available ); }