mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Fixed creating community
This commit is contained in:
@ -14,6 +14,7 @@ class SpaceManagementBloc
|
|||||||
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
||||||
on<CreateSpaceEvent>(_onCreateSpace);
|
on<CreateSpaceEvent>(_onCreateSpace);
|
||||||
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
||||||
|
on<CreateCommunityEvent>(_onCreateCommunity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onLoadCommunityAndSpaces(
|
void _onLoadCommunityAndSpaces(
|
||||||
@ -68,22 +69,28 @@ class SpaceManagementBloc
|
|||||||
// Handle space position update logic
|
// Handle space position update logic
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onCreateCommunity(
|
void _onCreateCommunity(
|
||||||
CreateCommunityEvent event,
|
CreateCommunityEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
final previousState = state;
|
||||||
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommunityModel? community = await _api.createCommunity(
|
|
||||||
|
CommunityModel? newCommunity = await _api.createCommunity(
|
||||||
event.name,
|
event.name,
|
||||||
event.description,
|
event.description,
|
||||||
event.regionId,
|
event.regionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (community != null) {
|
if (newCommunity != null) {
|
||||||
List<CommunityModel> updatedCommunities = List.from((state as SpaceManagementLoaded).communities)
|
if (previousState is SpaceManagementLoaded) {
|
||||||
..add(community); // Add the newly created community to the list
|
final updatedCommunities =
|
||||||
|
List<CommunityModel>.from(previousState.communities)
|
||||||
emit(SpaceManagementLoaded(communities: updatedCommunities));
|
..add(newCommunity);
|
||||||
|
emit(SpaceManagementLoaded(communities: updatedCommunities));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
emit(const SpaceManagementError('Error creating community'));
|
emit(const SpaceManagementError('Error creating community'));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class CreateCommunityDialog extends StatefulWidget {
|
class CreateCommunityDialog extends StatefulWidget {
|
||||||
final Function(String) onCreateCommunity;
|
final Function(String name, String description, String regionId)
|
||||||
|
onCreateCommunity;
|
||||||
|
|
||||||
const CreateCommunityDialog({super.key, required this.onCreateCommunity});
|
const CreateCommunityDialog({super.key, required this.onCreateCommunity});
|
||||||
|
|
||||||
@ -109,7 +110,11 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (enteredName.isNotEmpty) {
|
if (enteredName.isNotEmpty) {
|
||||||
widget.onCreateCommunity(enteredName);
|
widget.onCreateCommunity(
|
||||||
|
enteredName,
|
||||||
|
"",
|
||||||
|
"42dc377a-1a39-4df9-b85a-b3817af88525",
|
||||||
|
);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:syncrow_web/common/search_bar.dart';
|
import 'package:syncrow_web/common/search_bar.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/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/model/space_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
||||||
@ -30,14 +33,19 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showCreateCommunityDialog() {
|
void _showCreateCommunityDialog(BuildContext parentContext) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: parentContext,
|
||||||
builder: (context) => CreateCommunityDialog(
|
builder: (context) => CreateCommunityDialog(
|
||||||
onCreateCommunity: (String communityName) {
|
onCreateCommunity:
|
||||||
setState(() {
|
(String communityName, String description, String regionId) {
|
||||||
// You can update the community list here when a new community is added
|
parentContext.read<SpaceManagementBloc>().add(
|
||||||
});
|
CreateCommunityEvent(
|
||||||
|
name: communityName,
|
||||||
|
description: description,
|
||||||
|
regionId: regionId,
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -122,7 +130,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
style: Theme.of(context).textTheme.titleMedium,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: _showCreateCommunityDialog,
|
onTap: () => _showCreateCommunityDialog(context),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 30,
|
width: 30,
|
||||||
height: 30,
|
height: 30,
|
||||||
|
Reference in New Issue
Block a user