community title will list from the api

This commit is contained in:
hannathkadher
2024-10-02 12:03:34 +04:00
parent 5d397691b6
commit 308a7adba7
4 changed files with 140 additions and 77 deletions

View File

@ -4,12 +4,15 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/common/custom_expansion_tile.dart';
import 'package:syncrow_web/pages/common/buttons/add_space_button.dart';
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_space_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/view/sidebar_widget.dart';
import 'package:syncrow_web/services/space_mana_api.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
class SpaceManagementPage extends StatefulWidget{
class SpaceManagementPage extends StatefulWidget {
@override
SpaceManagementPageState createState() => SpaceManagementPageState();
}
@ -19,6 +22,41 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
List<SpaceData> spaces = [];
List<Connection> connections = [];
// API instance
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
// Data structure to store community and associated spaces
Map<String, List<SpaceModel>> communitySpaces = {};
@override
void initState() {
super.initState();
_loadCommunityAndSpacesData();
}
// Function to load all communities and their respective spaces
void _loadCommunityAndSpacesData() async {
try {
// Fetch all communities
List<CommunityModel> communities = await _api.fetchCommunities();
for (CommunityModel community in communities) {
// Fetch spaces hierarchy for each community
List<SpaceModel> spaces = await _api.getSpaceHierarchy(community.uuid);
// Store the result in the communitySpaces map
communitySpaces[community.name] = spaces;
}
// Update the state to reflect loaded data
setState(() {
// Optionally, you can initialize something here based on the loaded data
});
} catch (e) {
debugPrint('Error loading communities and spaces: $e');
}
}
void _handleCommunitySelection(String community) {
// Handle community selection here
print("Selected Community: $community");
@ -40,6 +78,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
children: [
// Sidebar for navigation and community list
SidebarWidget(
communitySpaces: communitySpaces, // Pass communitySpaces here
onCommunitySelected: _handleCommunitySelection,
),
// Right Side: Community Structure Area