mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added bloc for create community
This commit is contained in:
@ -67,4 +67,28 @@ class SpaceManagementBloc
|
||||
) {
|
||||
// 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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,3 +44,19 @@ class UpdateSpacePositionEvent extends SpaceManagementEvent {
|
||||
@override
|
||||
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];
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:equatable/equatable.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 {
|
||||
const SpaceManagementState();
|
||||
@ -16,7 +15,6 @@ class SpaceManagementLoading extends SpaceManagementState {}
|
||||
class SpaceManagementLoaded extends SpaceManagementState {
|
||||
final List<CommunityModel> communities;
|
||||
|
||||
|
||||
const SpaceManagementLoaded({required this.communities});
|
||||
|
||||
@override
|
||||
|
Reference in New Issue
Block a user