added the tap gesture for creating community

This commit is contained in:
hannathkadher
2024-10-02 12:19:49 +04:00
parent 559989cdec
commit 0d2d343bf8

View File

@ -4,6 +4,7 @@ import 'package:syncrow_web/common/custom_expansion_tile.dart';
import 'package:syncrow_web/common/search_bar.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/view/community_tile.dart';
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_community_dialog.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/style.dart';
@ -40,13 +41,29 @@ class _SidebarWidgetState extends State<SidebarWidget> {
// Helper function to log the spaces and their children
void _logSpaces(List<SpaceModel> spaces, int level) {
for (SpaceModel space in spaces) {
debugPrint('${' ' * level}Space: ${space.name}, UUID: ${space.uuid}, Has children: ${space.children.isNotEmpty}');
debugPrint(
'${' ' * level}Space: ${space.name}, UUID: ${space.uuid}, Has children: ${space.children.isNotEmpty}');
if (space.children.isNotEmpty) {
_logSpaces(space.children, level + 1);
}
}
}
void _showCreateCommunityDialog() {
showDialog(
context: context,
builder: (context) => CreateCommunityDialog(
onCreateCommunity: (String communityName) {
setState(() {
debugPrint("hello");
// You can update the communitySpaces map here
});
},
),
);
}
// Function to filter communities based on the search query
Map<String, List<SpaceModel>> _filterCommunities() {
if (_searchQuery.isEmpty) {
@ -57,8 +74,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
final filteredCommunitySpaces = <String, List<SpaceModel>>{};
widget.communitySpaces.forEach((communityName, spaces) {
if (communityName.toLowerCase().contains(_searchQuery.toLowerCase()) ||
spaces.any((space) =>
_containsQuery(space, _searchQuery.toLowerCase()))) {
spaces.any(
(space) => _containsQuery(space, _searchQuery.toLowerCase()))) {
filteredCommunitySpaces[communityName] = spaces;
}
});
@ -101,7 +118,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
),
GestureDetector(
onTap: () {
// Handle add button action
_showCreateCommunityDialog();
},
child: Container(
width: 30,
@ -135,7 +152,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
Expanded(
child: ListView(
children: filteredCommunities.keys.map((communityName) {
return _buildCommunityTile(communityName, filteredCommunities[communityName]!);
return _buildCommunityTile(
communityName, filteredCommunities[communityName]!);
}).toList(),
),
),
@ -147,12 +165,14 @@ class _SidebarWidgetState extends State<SidebarWidget> {
Widget _buildCommunityTile(String communityName, List<SpaceModel> spaces) {
bool hasChildren = spaces.isNotEmpty;
debugPrint('Building CommunityTile for $communityName, hasChildren: $hasChildren');
debugPrint(
'Building CommunityTile for $communityName, hasChildren: $hasChildren');
return CommunityTile(
title: communityName,
isExpanded: _expandedTiles[communityName] ?? false,
onExpansionChanged: (String title, bool expanded) {
debugPrint('CommunityTile onExpansionChanged called for $title, expanded: $expanded');
debugPrint(
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
_handleExpansionChange(title, expanded);
},
children: hasChildren
@ -162,16 +182,20 @@ class _SidebarWidgetState extends State<SidebarWidget> {
}
Widget _buildSpaceTile(SpaceModel space) {
debugPrint('Building SpaceTile for ${space.name}, hasChildren: ${space.children.isNotEmpty}');
debugPrint(
'Building SpaceTile for ${space.name}, hasChildren: ${space.children.isNotEmpty}');
return CustomExpansionTile(
title: space.name,
isExpanded: _expandedTiles[space.uuid] ?? false,
onExpansionChanged: (bool expanded) {
debugPrint('SpaceTile onExpansionChanged called for ${space.name}, expanded: $expanded');
debugPrint(
'SpaceTile onExpansionChanged called for ${space.name}, expanded: $expanded');
_handleExpansionChange(space.uuid, expanded);
},
children: space.children.isNotEmpty
? space.children.map((childSpace) => _buildSpaceTile(childSpace)).toList()
? space.children
.map((childSpace) => _buildSpaceTile(childSpace))
.toList()
: [], // Recursively render child spaces if available
);
}