mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
removed unnecessary comments from SidebarWidget
.
This commit is contained in:
@ -29,15 +29,14 @@ class SidebarWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
String _searchQuery = ''; // Track search query
|
||||
String _searchQuery = '';
|
||||
String? _selectedSpaceUuid;
|
||||
String? _selectedId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedId =
|
||||
widget.selectedSpaceUuid; // Initialize with the passed selected space UUID
|
||||
_selectedId = widget.selectedSpaceUuid;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -50,15 +49,12 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
// Function to filter communities based on the search query
|
||||
List<CommunityModel> _filterCommunities() {
|
||||
if (_searchQuery.isEmpty) {
|
||||
// Reset the selected community and space UUIDs if there's no query
|
||||
_selectedSpaceUuid = null;
|
||||
return widget.communities;
|
||||
}
|
||||
|
||||
// Filter communities and expand only those that match the query
|
||||
return widget.communities.where((community) {
|
||||
final containsQueryInCommunity =
|
||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||
@ -69,13 +65,12 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// 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
|
||||
(child) => _containsQuery(child, query),
|
||||
);
|
||||
|
||||
// If the space or any of its children match the query, expand this space
|
||||
if (matchesSpace || matchesChildren) {
|
||||
_selectedSpaceUuid = space.uuid;
|
||||
}
|
||||
@ -84,12 +79,10 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
}
|
||||
|
||||
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 (_isSpaceOrChildSelected(child)) {
|
||||
return true;
|
||||
@ -107,11 +100,9 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
width: 300,
|
||||
decoration: subSectionContainerDecoration,
|
||||
child: Column(
|
||||
mainAxisSize:
|
||||
MainAxisSize.min, // Ensures the Column only takes necessary height
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Communities title with the add button
|
||||
Container(
|
||||
decoration: subSectionContainerDecoration,
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
@ -143,7 +134,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
],
|
||||
),
|
||||
),
|
||||
// Search bar
|
||||
CustomSearchBar(
|
||||
onSearchChanged: (query) {
|
||||
setState(() {
|
||||
@ -152,7 +142,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Community list
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: filteredCommunities
|
||||
@ -185,7 +174,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
onItemSelected: () {
|
||||
setState(() {
|
||||
_selectedId = community.uuid;
|
||||
_selectedSpaceUuid = null; // Update the selected community
|
||||
_selectedSpaceUuid = null;
|
||||
});
|
||||
|
||||
context.read<CenterBodyBloc>().add(CommunitySelectedEvent());
|
||||
@ -231,7 +220,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
? space.children
|
||||
.map((childSpace) => _buildSpaceTile(childSpace, community))
|
||||
.toList()
|
||||
: [], // Recursively render child spaces if available
|
||||
: [],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user