mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +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 {
|
class CommunityStructureArea extends StatefulWidget {
|
||||||
final CommunityModel? selectedCommunity;
|
final CommunityModel? selectedCommunity;
|
||||||
final SpaceModel? selectedSpace;
|
SpaceModel? selectedSpace;
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
|
final ValueChanged<SpaceModel?>? onSpaceSelected;
|
||||||
|
|
||||||
final List<SpaceModel> spaces;
|
final List<SpaceModel> spaces;
|
||||||
final List<Connection> connections;
|
final List<Connection> connections;
|
||||||
@ -31,6 +32,7 @@ class CommunityStructureArea extends StatefulWidget {
|
|||||||
this.products,
|
this.products,
|
||||||
required this.spaces,
|
required this.spaces,
|
||||||
required this.connections,
|
required this.connections,
|
||||||
|
this.onSpaceSelected,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -150,7 +152,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
onDoubleTap: () {
|
onDoubleTap: () {
|
||||||
_showEditSpaceDialog(visibleSpaces[index]);
|
_showEditSpaceDialog(visibleSpaces[index]);
|
||||||
},
|
},
|
||||||
onTap: (){
|
onTap: () {
|
||||||
_selectSpace(visibleSpaces[index]);
|
_selectSpace(visibleSpaces[index]);
|
||||||
},
|
},
|
||||||
icon: visibleSpaces[index].icon ?? '',
|
icon: visibleSpaces[index].icon ?? '',
|
||||||
@ -559,8 +561,13 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
..scale(1.2);
|
..scale(1.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _selectSpace(SpaceModel space){
|
void _selectSpace(SpaceModel space) {
|
||||||
print(space.name);
|
setState(() {
|
||||||
}
|
widget.selectedSpace = space;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (widget.onSpaceSelected != null) {
|
||||||
|
widget.onSpaceSelected!(space);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,16 +37,29 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SidebarWidget(
|
SidebarWidget(
|
||||||
communities: widget.communities,
|
communities: widget.communities,
|
||||||
onCommunitySelected: widget.onCommunitySelected,
|
onCommunitySelected: widget.onCommunitySelected,
|
||||||
onSpaceSelected: widget.onSpaceSelected,
|
onSpaceSelected: widget.onSpaceSelected,
|
||||||
),
|
selectedSpaceUuid: widget.selectedSpace?.uuid,
|
||||||
|
onSelectedSpaceChanged: (String? spaceUuid) {
|
||||||
|
setState(() {
|
||||||
|
final selectedSpace = findSpaceByUuid(spaceUuid, widget.communities);
|
||||||
|
if (selectedSpace != null) {
|
||||||
|
widget.onSpaceSelected!(selectedSpace);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
CommunityStructureArea(
|
CommunityStructureArea(
|
||||||
selectedCommunity: widget.selectedCommunity,
|
selectedCommunity: widget.selectedCommunity,
|
||||||
selectedSpace: widget.selectedSpace,
|
selectedSpace: widget.selectedSpace,
|
||||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||||
connections: [],
|
connections: const [],
|
||||||
products: widget.products,
|
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(CommunityModel)? onCommunitySelected;
|
||||||
final Function(SpaceModel?)? onSpaceSelected;
|
final Function(SpaceModel?)? onSpaceSelected;
|
||||||
final List<CommunityModel> communities;
|
final List<CommunityModel> communities;
|
||||||
|
final Function(String?)? onSelectedSpaceChanged; // New callback
|
||||||
|
|
||||||
const SidebarWidget(
|
final String? selectedSpaceUuid;
|
||||||
{super.key, this.onCommunitySelected, this.onSpaceSelected, required this.communities});
|
|
||||||
|
const SidebarWidget({
|
||||||
|
super.key,
|
||||||
|
this.onCommunitySelected,
|
||||||
|
this.onSpaceSelected,
|
||||||
|
this.onSelectedSpaceChanged,
|
||||||
|
required this.communities,
|
||||||
|
this.selectedSpaceUuid,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SidebarWidgetState createState() => _SidebarWidgetState();
|
_SidebarWidgetState createState() => _SidebarWidgetState();
|
||||||
@ -27,13 +36,23 @@ class SidebarWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _SidebarWidgetState extends State<SidebarWidget> {
|
class _SidebarWidgetState extends State<SidebarWidget> {
|
||||||
String _searchQuery = ''; // Track search query
|
String _searchQuery = ''; // Track search query
|
||||||
String? _selectedCommunityUuid;
|
|
||||||
String? _selectedSpaceUuid;
|
String? _selectedSpaceUuid;
|
||||||
String? _selectedId;
|
String? _selectedId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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) {
|
void _showCreateCommunityDialog(BuildContext parentContext) {
|
||||||
@ -57,7 +76,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
List<CommunityModel> _filterCommunities() {
|
List<CommunityModel> _filterCommunities() {
|
||||||
if (_searchQuery.isEmpty) {
|
if (_searchQuery.isEmpty) {
|
||||||
// Reset the selected community and space UUIDs if there's no query
|
// Reset the selected community and space UUIDs if there's no query
|
||||||
_selectedCommunityUuid = null;
|
|
||||||
_selectedSpaceUuid = null;
|
_selectedSpaceUuid = null;
|
||||||
return widget.communities;
|
return widget.communities;
|
||||||
}
|
}
|
||||||
@ -69,9 +87,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
final containsQueryInSpaces =
|
final containsQueryInSpaces =
|
||||||
community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
community.spaces.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();
|
||||||
@ -174,9 +190,7 @@ 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;
|
|
||||||
|
|
||||||
// Check if this community is selected
|
|
||||||
return CommunityTile(
|
return CommunityTile(
|
||||||
title: community.name,
|
title: community.name,
|
||||||
key: ValueKey(community.uuid),
|
key: ValueKey(community.uuid),
|
||||||
@ -185,7 +199,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
onItemSelected: () {
|
onItemSelected: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedId = community.uuid;
|
_selectedId = community.uuid;
|
||||||
_selectedCommunityUuid = community.uuid;
|
|
||||||
_selectedSpaceUuid = null; // Update the selected community
|
_selectedSpaceUuid = null; // Update the selected community
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -218,12 +231,16 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_selectedId = space.uuid;
|
_selectedId = space.uuid;
|
||||||
_selectedSpaceUuid = space.uuid;
|
_selectedSpaceUuid = space.uuid;
|
||||||
_selectedCommunityUuid = community.uuid; // Update selected community
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (widget.onSpaceSelected != null) {
|
if (widget.onSpaceSelected != null) {
|
||||||
widget.onCommunitySelected!(community);
|
widget.onCommunitySelected!(community);
|
||||||
widget.onSpaceSelected!(space);
|
widget.onSpaceSelected!(space);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (widget.onSelectedSpaceChanged != null) {
|
||||||
|
widget.onSelectedSpaceChanged!(space.uuid);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
children: space.children.isNotEmpty
|
children: space.children.isNotEmpty
|
||||||
? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList()
|
? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList()
|
||||||
|
@ -22,6 +22,7 @@ class SpaceContainerWidget extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onDoubleTap: onDoubleTap,
|
onDoubleTap: onDoubleTap,
|
||||||
|
onTap: onTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 150,
|
width: 150,
|
||||||
height: 60,
|
height: 60,
|
||||||
|
Reference in New Issue
Block a user