mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-16 01:56:24 +00:00
fixed space select
This commit is contained in:
@ -17,9 +17,18 @@ class SidebarWidget extends StatefulWidget {
|
||||
final Function(CommunityModel)? onCommunitySelected;
|
||||
final Function(SpaceModel?)? onSpaceSelected;
|
||||
final List<CommunityModel> communities;
|
||||
final Function(String?)? onSelectedSpaceChanged; // New callback
|
||||
|
||||
const SidebarWidget(
|
||||
{super.key, this.onCommunitySelected, this.onSpaceSelected, required this.communities});
|
||||
final String? selectedSpaceUuid;
|
||||
|
||||
const SidebarWidget({
|
||||
super.key,
|
||||
this.onCommunitySelected,
|
||||
this.onSpaceSelected,
|
||||
this.onSelectedSpaceChanged,
|
||||
required this.communities,
|
||||
this.selectedSpaceUuid,
|
||||
});
|
||||
|
||||
@override
|
||||
_SidebarWidgetState createState() => _SidebarWidgetState();
|
||||
@ -27,13 +36,23 @@ class SidebarWidget extends StatefulWidget {
|
||||
|
||||
class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
String _searchQuery = ''; // Track search query
|
||||
String? _selectedCommunityUuid;
|
||||
String? _selectedSpaceUuid;
|
||||
String? _selectedId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SidebarWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid) {
|
||||
setState(() {
|
||||
_selectedId = widget.selectedSpaceUuid;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _showCreateCommunityDialog(BuildContext parentContext) {
|
||||
@ -57,7 +76,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
List<CommunityModel> _filterCommunities() {
|
||||
if (_searchQuery.isEmpty) {
|
||||
// Reset the selected community and space UUIDs if there's no query
|
||||
_selectedCommunityUuid = null;
|
||||
_selectedSpaceUuid = null;
|
||||
return widget.communities;
|
||||
}
|
||||
@ -69,9 +87,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
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();
|
||||
@ -174,9 +190,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
|
||||
Widget _buildCommunityTile(CommunityModel community) {
|
||||
bool hasChildren = community.spaces.isNotEmpty;
|
||||
bool isSelectedCommunity = _selectedCommunityUuid == community.uuid;
|
||||
|
||||
// Check if this community is selected
|
||||
return CommunityTile(
|
||||
title: community.name,
|
||||
key: ValueKey(community.uuid),
|
||||
@ -185,7 +199,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
onItemSelected: () {
|
||||
setState(() {
|
||||
_selectedId = community.uuid;
|
||||
_selectedCommunityUuid = community.uuid;
|
||||
_selectedSpaceUuid = null; // Update the selected community
|
||||
});
|
||||
|
||||
@ -218,12 +231,16 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
setState(() {
|
||||
_selectedId = space.uuid;
|
||||
_selectedSpaceUuid = space.uuid;
|
||||
_selectedCommunityUuid = community.uuid; // Update selected community
|
||||
});
|
||||
|
||||
if (widget.onSpaceSelected != null) {
|
||||
widget.onCommunitySelected!(community);
|
||||
widget.onSpaceSelected!(space);
|
||||
}
|
||||
|
||||
if (widget.onSelectedSpaceChanged != null) {
|
||||
widget.onSelectedSpaceChanged!(space.uuid);
|
||||
}
|
||||
},
|
||||
children: space.children.isNotEmpty
|
||||
? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList()
|
||||
|
Reference in New Issue
Block a user