mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
selecting space selects community
This commit is contained in:
@ -17,8 +17,7 @@ class SidebarWidget extends StatefulWidget {
|
||||
final Function(CommunityModel)? onCommunitySelected;
|
||||
final List<CommunityModel> communities;
|
||||
|
||||
const SidebarWidget(
|
||||
{super.key, this.onCommunitySelected, required this.communities});
|
||||
const SidebarWidget({super.key, this.onCommunitySelected, required this.communities});
|
||||
|
||||
@override
|
||||
_SidebarWidgetState createState() => _SidebarWidgetState();
|
||||
@ -38,8 +37,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
showDialog(
|
||||
context: parentContext,
|
||||
builder: (context) => CreateCommunityDialog(
|
||||
onCreateCommunity:
|
||||
(String communityName, String description, String regionId) {
|
||||
onCreateCommunity: (String communityName, String description, String regionId) {
|
||||
parentContext.read<SpaceManagementBloc>().add(
|
||||
CreateCommunityEvent(
|
||||
name: communityName,
|
||||
@ -65,12 +63,11 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
return widget.communities.where((community) {
|
||||
final containsQueryInCommunity =
|
||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||
final containsQueryInSpaces = community.spaces
|
||||
.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||
final containsQueryInSpaces =
|
||||
community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||
|
||||
if (containsQueryInCommunity || containsQueryInSpaces) {
|
||||
_selectedCommunityUuid =
|
||||
community.uuid; // Set the community to expanded
|
||||
_selectedCommunityUuid = community.uuid; // Set the community to expanded
|
||||
}
|
||||
|
||||
return containsQueryInCommunity || containsQueryInSpaces;
|
||||
@ -80,8 +77,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
// 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
|
||||
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) {
|
||||
@ -115,8 +112,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
width: 300,
|
||||
decoration: subSectionContainerDecoration,
|
||||
child: Column(
|
||||
mainAxisSize:
|
||||
MainAxisSize.min, // Ensures the Column only takes necessary height
|
||||
mainAxisSize: MainAxisSize.min, // Ensures the Column only takes necessary height
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Communities title with the add button
|
||||
@ -175,8 +171,8 @@ 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
|
||||
bool isSelectedCommunity =
|
||||
_selectedCommunityUuid == community.uuid; // Check if this community is selected
|
||||
return CommunityTile(
|
||||
title: community.name,
|
||||
isSelected: isSelectedCommunity,
|
||||
@ -194,24 +190,28 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
_handleExpansionChange(community.uuid, expanded);
|
||||
},
|
||||
children: hasChildren
|
||||
? community.spaces.map((space) => _buildSpaceTile(space)).toList()
|
||||
? community.spaces.map((space) => _buildSpaceTile(space, community)).toList()
|
||||
: null, // Render spaces within the community
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSpaceTile(SpaceModel space) {
|
||||
bool isSelectedSpace =
|
||||
_isSpaceOrChildSelected(space); // Check if space should be expanded
|
||||
Widget _buildSpaceTile(SpaceModel space, CommunityModel community) {
|
||||
bool isSelectedSpace = _isSpaceOrChildSelected(space); // Check if space should be expanded
|
||||
return SpaceTile(
|
||||
title: space.name,
|
||||
isSelected: isSelectedSpace,
|
||||
initiallyExpanded: isSelectedSpace,
|
||||
onExpansionChanged: (bool expanded) {
|
||||
_handleExpansionChange(space.uuid ?? '', expanded);
|
||||
},
|
||||
onItemSelected: () => {
|
||||
if (widget.onCommunitySelected != null)
|
||||
{
|
||||
widget.onCommunitySelected!(community) // Pass the entire community
|
||||
}
|
||||
},
|
||||
children: space.children.isNotEmpty
|
||||
? space.children
|
||||
.map((childSpace) => _buildSpaceTile(childSpace))
|
||||
.toList()
|
||||
? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList()
|
||||
: [], // Recursively render child spaces if available
|
||||
);
|
||||
}
|
||||
|
@ -3,15 +3,20 @@ import 'package:syncrow_web/common/custom_expansion_tile.dart';
|
||||
|
||||
class SpaceTile extends StatefulWidget {
|
||||
final String title;
|
||||
final bool isSelected;
|
||||
|
||||
final bool initiallyExpanded;
|
||||
final ValueChanged<bool> onExpansionChanged;
|
||||
final List<Widget>? children;
|
||||
final Function() onItemSelected;
|
||||
|
||||
const SpaceTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.initiallyExpanded,
|
||||
required this.onExpansionChanged,
|
||||
required this.onItemSelected,
|
||||
required this.isSelected,
|
||||
this.children,
|
||||
});
|
||||
|
||||
@ -34,6 +39,7 @@ class _SpaceTileState extends State<SpaceTile> {
|
||||
isSelected: false,
|
||||
title: widget.title,
|
||||
initiallyExpanded: _isExpanded,
|
||||
onItemSelected: widget.onItemSelected,
|
||||
onExpansionChanged: (bool expanded) {
|
||||
setState(() {
|
||||
_isExpanded = expanded;
|
||||
|
Reference in New Issue
Block a user