mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
73 lines
2.8 KiB
Dart
73 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_state.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/model/connection_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/model/space_data_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/widgets/loaded_space_widget.dart';
|
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
|
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
|
|
|
class SpaceManagementPage extends StatefulWidget {
|
|
const SpaceManagementPage({super.key});
|
|
|
|
@override
|
|
SpaceManagementPageState createState() => SpaceManagementPageState();
|
|
}
|
|
|
|
class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|
CommunityModel? selectedCommunity;
|
|
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
|
|
Map<String, List<SpaceModel>> communitySpaces = {};
|
|
double canvasWidth = 1000;
|
|
double canvasHeight = 1000;
|
|
List<SpaceData> spaces = [];
|
|
List<Connection> connections = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider(
|
|
create: (context) =>
|
|
SpaceManagementBloc(CommunitySpaceManagementApi())..add(LoadCommunityAndSpacesEvent()),
|
|
child: WebScaffold(
|
|
appBarTitle: Text('Space Management', style: Theme.of(context).textTheme.headlineLarge),
|
|
enableMenuSidebar: false,
|
|
scaffoldBody:
|
|
BlocBuilder<SpaceManagementBloc, SpaceManagementState>(builder: (context, state) {
|
|
if (state is SpaceManagementLoading) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (state is SpaceManagementLoaded) {
|
|
int selectedIndex = state.communities.indexWhere(
|
|
(community) => community.uuid == selectedCommunity?.uuid,
|
|
);
|
|
if (selectedIndex != -1) {
|
|
selectedCommunity = state.communities[selectedIndex];
|
|
}
|
|
|
|
return LoadedSpaceView(
|
|
communities: state.communities,
|
|
selectedCommunity: selectedCommunity,
|
|
onCommunitySelected: (community) {
|
|
setState(() {
|
|
selectedCommunity = community;
|
|
});
|
|
},
|
|
);
|
|
} else if (state is SpaceManagementError) {
|
|
return Center(child: Text('Error: ${state.errorMessage}'));
|
|
}
|
|
return Container();
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|