mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
filtering
This commit is contained in:
@ -95,9 +95,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
_capitalizeFirstLetter(widget.title),
|
_capitalizeFirstLetter(widget.title),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: _isExpanded
|
color:ColorsManager.lightGrayColor,
|
||||||
? ColorsManager.blackColor
|
|
||||||
: ColorsManager.lightGrayColor,
|
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -22,7 +22,8 @@ class SidebarWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _SidebarWidgetState extends State<SidebarWidget> {
|
class _SidebarWidgetState extends State<SidebarWidget> {
|
||||||
String _searchQuery = ''; // Track search query
|
String _searchQuery = ''; // Track search query
|
||||||
Map<String, bool> _expandedTiles = {}; // Track expanded state for each UUID
|
String? _selectedCommunityUuid;
|
||||||
|
String? _selectedSpaceUuid;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -45,29 +46,55 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
// Function to filter communities based on the search query
|
// Function to filter communities based on the search query
|
||||||
List<CommunityModel> _filterCommunities() {
|
List<CommunityModel> _filterCommunities() {
|
||||||
if (_searchQuery.isEmpty) {
|
if (_searchQuery.isEmpty) {
|
||||||
|
// Reset the selected community and space UUIDs if there's no query
|
||||||
|
_selectedCommunityUuid = null;
|
||||||
|
_selectedSpaceUuid = null;
|
||||||
return widget.communities;
|
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) {
|
return widget.communities.where((community) {
|
||||||
final containsQueryInCommunity =
|
final containsQueryInCommunity =
|
||||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||||
final containsQueryInSpaces = community.spaces
|
final containsQueryInSpaces = community.spaces
|
||||||
.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||||
|
|
||||||
|
if (containsQueryInCommunity || containsQueryInSpaces) {
|
||||||
|
_selectedCommunityUuid =
|
||||||
|
community.uuid; // Set the community to expanded
|
||||||
|
}
|
||||||
|
|
||||||
return containsQueryInCommunity || containsQueryInSpaces;
|
return containsQueryInCommunity || containsQueryInSpaces;
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to determine if any space or its children match the search query
|
// Helper function to determine if any space or its children match the search query
|
||||||
bool _containsQuery(SpaceModel space, String 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recursively check if any child spaces match the query
|
||||||
for (var child in space.children) {
|
for (var child in space.children) {
|
||||||
if (_containsQuery(child, query)) {
|
if (_isSpaceOrChildSelected(child)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +166,13 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
|
|
||||||
Widget _buildCommunityTile(CommunityModel community) {
|
Widget _buildCommunityTile(CommunityModel community) {
|
||||||
bool hasChildren = community.spaces.isNotEmpty;
|
bool hasChildren = community.spaces.isNotEmpty;
|
||||||
|
bool isSelectedCommunity = _selectedCommunityUuid == community.uuid;
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'Building CommunityTile for ${community.name}, hasChildren: $hasChildren');
|
'Building CommunityTile for ${community.name}, hasChildren: $hasChildren');
|
||||||
return CommunityTile(
|
return CommunityTile(
|
||||||
title: community.name,
|
title: community.name,
|
||||||
initiallyExpanded: false,
|
initiallyExpanded: isSelectedCommunity,
|
||||||
onExpansionChanged: (String title, bool expanded) {
|
onExpansionChanged: (String title, bool expanded) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
|
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
|
||||||
@ -157,11 +185,14 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSpaceTile(SpaceModel space) {
|
Widget _buildSpaceTile(SpaceModel space) {
|
||||||
|
bool isSelectedSpace =
|
||||||
|
_isSpaceOrChildSelected(space); // Check if space should be expanded
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'Building SpaceTile for ${space.name}, hasChildren: ${space.children.isNotEmpty}');
|
'Building SpaceTile for ${space.name}, hasChildren: ${space.children.isNotEmpty}');
|
||||||
return SpaceTile(
|
return SpaceTile(
|
||||||
title: space.name,
|
title: space.name,
|
||||||
initiallyExpanded: false,
|
initiallyExpanded: isSelectedSpace,
|
||||||
onExpansionChanged: (bool expanded) {
|
onExpansionChanged: (bool expanded) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'SpaceTile onExpansionChanged called for ${space.name}, expanded: $expanded');
|
'SpaceTile onExpansionChanged called for ${space.name}, expanded: $expanded');
|
||||||
|
Reference in New Issue
Block a user