added bloc for create community

This commit is contained in:
hannathkadher
2024-10-09 11:04:56 +04:00
parent 4e7aba3983
commit f285189e42
3 changed files with 41 additions and 3 deletions

View File

@ -67,4 +67,28 @@ class SpaceManagementBloc
) { ) {
// Handle space position update logic // Handle space position update logic
} }
void _onCreateCommunity(
CreateCommunityEvent event,
Emitter<SpaceManagementState> emit,
) async {
try {
CommunityModel? community = await _api.createCommunity(
event.name,
event.description,
event.regionId,
);
if (community != null) {
List<CommunityModel> updatedCommunities = List.from((state as SpaceManagementLoaded).communities)
..add(community); // Add the newly created community to the list
emit(SpaceManagementLoaded(communities: updatedCommunities));
} else {
emit(const SpaceManagementError('Error creating community'));
}
} catch (e) {
emit(SpaceManagementError('Error creating community: $e'));
}
}
} }

View File

@ -44,3 +44,19 @@ class UpdateSpacePositionEvent extends SpaceManagementEvent {
@override @override
List<Object> get props => [index, newPosition]; List<Object> get props => [index, newPosition];
} }
class CreateCommunityEvent extends SpaceManagementEvent {
final String name;
final String description;
final String regionId;
CreateCommunityEvent({
required this.name,
required this.description,
required this.regionId,
});
@override
List<Object> get props => [name, description, regionId];
}

View File

@ -1,6 +1,5 @@
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.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';
abstract class SpaceManagementState extends Equatable { abstract class SpaceManagementState extends Equatable {
const SpaceManagementState(); const SpaceManagementState();
@ -16,8 +15,7 @@ class SpaceManagementLoading extends SpaceManagementState {}
class SpaceManagementLoaded extends SpaceManagementState { class SpaceManagementLoaded extends SpaceManagementState {
final List<CommunityModel> communities; final List<CommunityModel> communities;
const SpaceManagementLoaded({required this.communities});
const SpaceManagementLoaded({ required this.communities});
@override @override
List<Object> get props => [communities]; List<Object> get props => [communities];