pass selected space

This commit is contained in:
hannathkadher
2024-11-19 18:16:53 +04:00
parent a464788e88
commit 8a2efb2694
4 changed files with 29 additions and 8 deletions

View File

@ -20,6 +20,7 @@ class SpaceManagementPage extends StatefulWidget {
class SpaceManagementPageState extends State<SpaceManagementPage> { class SpaceManagementPageState extends State<SpaceManagementPage> {
CommunityModel? selectedCommunity; CommunityModel? selectedCommunity;
SpaceModel? selectedSpace;
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi(); final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
Map<String, List<SpaceModel>> communitySpaces = {}; Map<String, List<SpaceModel>> communitySpaces = {};
double canvasWidth = 1000; double canvasWidth = 1000;
@ -55,11 +56,17 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
return LoadedSpaceView( return LoadedSpaceView(
communities: state.communities, communities: state.communities,
selectedCommunity: selectedCommunity, selectedCommunity: selectedCommunity,
selectedSpace: selectedSpace,
onCommunitySelected: (community) { onCommunitySelected: (community) {
setState(() { setState(() {
selectedCommunity = community; selectedCommunity = community;
}); });
}, },
onSpaceSelected: (space) {
setState(() {
selectedSpace = space;
});
},
); );
} else if (state is SpaceManagementError) { } else if (state is SpaceManagementError) {
return Center(child: Text('Error: ${state.errorMessage}')); return Center(child: Text('Error: ${state.errorMessage}'));

View File

@ -14,11 +14,14 @@ import 'package:syncrow_web/utils/color_manager.dart';
class CommunityStructureArea extends StatefulWidget { class CommunityStructureArea extends StatefulWidget {
final CommunityModel? selectedCommunity; final CommunityModel? selectedCommunity;
final SpaceModel? selectedSpace;
final List<SpaceModel> spaces; final List<SpaceModel> spaces;
final List<Connection> connections; final List<Connection> connections;
CommunityStructureArea({ CommunityStructureArea({
this.selectedCommunity, this.selectedCommunity,
this.selectedSpace,
required this.spaces, required this.spaces,
required this.connections, required this.connections,
}); });
@ -161,7 +164,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
), ),
if (widget.selectedCommunity != null) if (widget.selectedCommunity != null)
Text( Text(
widget.selectedCommunity!.name, widget.selectedCommunity?.name ?? '',
style: const TextStyle(fontSize: 16, color: ColorsManager.blackColor), style: const TextStyle(fontSize: 16, color: ColorsManager.blackColor),
), ),
], ],
@ -350,5 +353,4 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
communityUuid: communityUuid, communityUuid: communityUuid,
)); ));
} }
} }

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/spaces_management/model/community_model.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/widgets/community_structure_widget.dart'; import 'package:syncrow_web/pages/spaces_management/widgets/community_structure_widget.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/gradient_canvas_border_widget.dart'; import 'package:syncrow_web/pages/spaces_management/widgets/gradient_canvas_border_widget.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/sidebar_widget.dart'; import 'package:syncrow_web/pages/spaces_management/widgets/sidebar_widget.dart';
@ -7,13 +8,17 @@ import 'package:syncrow_web/pages/spaces_management/widgets/sidebar_widget.dart'
class LoadedSpaceView extends StatefulWidget { class LoadedSpaceView extends StatefulWidget {
final List<CommunityModel> communities; final List<CommunityModel> communities;
final CommunityModel? selectedCommunity; final CommunityModel? selectedCommunity;
final SpaceModel? selectedSpace;
final ValueChanged<CommunityModel> onCommunitySelected; final ValueChanged<CommunityModel> onCommunitySelected;
final ValueChanged<SpaceModel> onSpaceSelected;
const LoadedSpaceView({ const LoadedSpaceView({
Key? key, Key? key,
required this.communities, required this.communities,
this.selectedCommunity, this.selectedCommunity,
this.selectedSpace,
required this.onCommunitySelected, required this.onCommunitySelected,
required this.onSpaceSelected,
}) : super(key: key); }) : super(key: key);
@override @override
@ -31,9 +36,11 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
SidebarWidget( SidebarWidget(
communities: widget.communities, communities: widget.communities,
onCommunitySelected: widget.onCommunitySelected, onCommunitySelected: widget.onCommunitySelected,
onSpaceSelected: widget.onSpaceSelected,
), ),
CommunityStructureArea( CommunityStructureArea(
selectedCommunity: widget.selectedCommunity, selectedCommunity: widget.selectedCommunity,
selectedSpace: widget.selectedSpace,
spaces: widget.selectedCommunity?.spaces ?? [], spaces: widget.selectedCommunity?.spaces ?? [],
connections: [], connections: [],
), ),

View File

@ -15,9 +15,11 @@ import 'package:syncrow_web/utils/style.dart';
class SidebarWidget extends StatefulWidget { class SidebarWidget extends StatefulWidget {
final Function(CommunityModel)? onCommunitySelected; final Function(CommunityModel)? onCommunitySelected;
final Function(SpaceModel)? onSpaceSelected;
final List<CommunityModel> communities; final List<CommunityModel> communities;
const SidebarWidget({super.key, this.onCommunitySelected, required this.communities}); const SidebarWidget(
{super.key, this.onCommunitySelected, this.onSpaceSelected, required this.communities});
@override @override
_SidebarWidgetState createState() => _SidebarWidgetState(); _SidebarWidgetState createState() => _SidebarWidgetState();
@ -204,10 +206,13 @@ class _SidebarWidgetState extends State<SidebarWidget> {
onExpansionChanged: (bool expanded) { onExpansionChanged: (bool expanded) {
_handleExpansionChange(space.uuid ?? '', expanded); _handleExpansionChange(space.uuid ?? '', expanded);
}, },
onItemSelected: () => { onItemSelected: () {
if (widget.onCommunitySelected != null) if (widget.onCommunitySelected != null || widget.onSpaceSelected != null) {
{ widget.onCommunitySelected!(community); // Pass the entire community
widget.onCommunitySelected!(community) // Pass the entire community }
if (widget.onSpaceSelected != null) {
widget.onSpaceSelected!(space); // Pass the entire community
} }
}, },
children: space.children.isNotEmpty children: space.children.isNotEmpty