mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed space select
This commit is contained in:
@ -19,8 +19,9 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class CommunityStructureArea extends StatefulWidget {
|
||||
final CommunityModel? selectedCommunity;
|
||||
final SpaceModel? selectedSpace;
|
||||
SpaceModel? selectedSpace;
|
||||
final List<ProductModel>? products;
|
||||
final ValueChanged<SpaceModel?>? onSpaceSelected;
|
||||
|
||||
final List<SpaceModel> spaces;
|
||||
final List<Connection> connections;
|
||||
@ -31,6 +32,7 @@ class CommunityStructureArea extends StatefulWidget {
|
||||
this.products,
|
||||
required this.spaces,
|
||||
required this.connections,
|
||||
this.onSpaceSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -150,7 +152,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
onDoubleTap: () {
|
||||
_showEditSpaceDialog(visibleSpaces[index]);
|
||||
},
|
||||
onTap: (){
|
||||
onTap: () {
|
||||
_selectSpace(visibleSpaces[index]);
|
||||
},
|
||||
icon: visibleSpaces[index].icon ?? '',
|
||||
@ -559,8 +561,13 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
..scale(1.2);
|
||||
}
|
||||
|
||||
void _selectSpace(SpaceModel space){
|
||||
print(space.name);
|
||||
}
|
||||
void _selectSpace(SpaceModel space) {
|
||||
setState(() {
|
||||
widget.selectedSpace = space;
|
||||
});
|
||||
|
||||
if (widget.onSpaceSelected != null) {
|
||||
widget.onSpaceSelected!(space);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,16 +37,29 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
|
||||
Row(
|
||||
children: [
|
||||
SidebarWidget(
|
||||
communities: widget.communities,
|
||||
onCommunitySelected: widget.onCommunitySelected,
|
||||
onSpaceSelected: widget.onSpaceSelected,
|
||||
),
|
||||
communities: widget.communities,
|
||||
onCommunitySelected: widget.onCommunitySelected,
|
||||
onSpaceSelected: widget.onSpaceSelected,
|
||||
selectedSpaceUuid: widget.selectedSpace?.uuid,
|
||||
onSelectedSpaceChanged: (String? spaceUuid) {
|
||||
setState(() {
|
||||
final selectedSpace = findSpaceByUuid(spaceUuid, widget.communities);
|
||||
if (selectedSpace != null) {
|
||||
widget.onSpaceSelected!(selectedSpace);
|
||||
}
|
||||
});
|
||||
}),
|
||||
CommunityStructureArea(
|
||||
selectedCommunity: widget.selectedCommunity,
|
||||
selectedSpace: widget.selectedSpace,
|
||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||
connections: [],
|
||||
connections: const [],
|
||||
products: widget.products,
|
||||
onSpaceSelected: (SpaceModel? space) {
|
||||
setState(() {
|
||||
widget.onSpaceSelected!(space);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -54,4 +67,13 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
SpaceModel? findSpaceByUuid(String? uuid, List<CommunityModel> communities) {
|
||||
for (var community in communities) {
|
||||
for (var space in community.spaces) {
|
||||
if (space.uuid == uuid) return space;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -22,6 +22,7 @@ class SpaceContainerWidget extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onDoubleTap: onDoubleTap,
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 150,
|
||||
height: 60,
|
||||
|
Reference in New Issue
Block a user