mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed delete community
This commit is contained in:
@ -19,6 +19,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
on<CreateCommunityEvent>(_onCreateCommunity);
|
||||
on<SaveSpacesEvent>(_onSaveSpaces);
|
||||
on<FetchProductsEvent>(_onFetchProducts);
|
||||
on<DeleteCommunityEvent>(_onCommunityDelete);
|
||||
}
|
||||
|
||||
void _onFetchProducts(
|
||||
@ -74,11 +75,29 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}
|
||||
}
|
||||
|
||||
void _onCommunityDelete(
|
||||
DeleteCommunityEvent event,
|
||||
Emitter<SpaceManagementState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(SpaceManagementLoading());
|
||||
|
||||
final success = await _api.deleteCommunity(event.communityUuid);
|
||||
if (success) {
|
||||
add(LoadCommunityAndSpacesEvent());
|
||||
} else {
|
||||
emit(const SpaceManagementError('Failed to delete the community.'));
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle unexpected errors
|
||||
emit(SpaceManagementError('Error saving spaces: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
void _onUpdateSpacePosition(
|
||||
UpdateSpacePositionEvent event,
|
||||
Emitter<SpaceManagementState> emit,
|
||||
) {
|
||||
// Handle space position update logic
|
||||
}
|
||||
|
||||
void _onCreateCommunity(
|
||||
@ -110,7 +129,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _onSaveSpaces(
|
||||
SaveSpacesEvent event,
|
||||
Emitter<SpaceManagementState> emit,
|
||||
@ -139,29 +157,26 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
if (space.uuid != null && space.uuid!.isNotEmpty) {
|
||||
// Call update if the space already has a UUID
|
||||
final response = await _api.updateSpace(
|
||||
communityId: communityUuid,
|
||||
spaceId: space.uuid!,
|
||||
name: space.name,
|
||||
parentId: space.parent?.uuid,
|
||||
isPrivate: space.isPrivate,
|
||||
position: space.position,
|
||||
icon: space.icon,
|
||||
direction: space.incomingConnection?.direction,
|
||||
products: space.selectedProducts
|
||||
);
|
||||
communityId: communityUuid,
|
||||
spaceId: space.uuid!,
|
||||
name: space.name,
|
||||
parentId: space.parent?.uuid,
|
||||
isPrivate: space.isPrivate,
|
||||
position: space.position,
|
||||
icon: space.icon,
|
||||
direction: space.incomingConnection?.direction,
|
||||
products: space.selectedProducts);
|
||||
} else {
|
||||
// Call create if the space does not have a UUID
|
||||
final response = await _api.createSpace(
|
||||
communityId: communityUuid,
|
||||
name: space.name,
|
||||
parentId: space.parent?.uuid,
|
||||
isPrivate: space.isPrivate,
|
||||
position: space.position,
|
||||
icon: space.icon,
|
||||
direction: space.incomingConnection?.direction,
|
||||
products: space.selectedProducts
|
||||
|
||||
);
|
||||
communityId: communityUuid,
|
||||
name: space.name,
|
||||
parentId: space.parent?.uuid,
|
||||
isPrivate: space.isPrivate,
|
||||
position: space.position,
|
||||
icon: space.icon,
|
||||
direction: space.incomingConnection?.direction,
|
||||
products: space.selectedProducts);
|
||||
space.uuid = response?.uuid;
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -11,6 +11,17 @@ abstract class SpaceManagementEvent extends Equatable {
|
||||
|
||||
class LoadCommunityAndSpacesEvent extends SpaceManagementEvent {}
|
||||
|
||||
class DeleteCommunityEvent extends SpaceManagementEvent {
|
||||
final String communityUuid;
|
||||
|
||||
const DeleteCommunityEvent({
|
||||
required this.communityUuid,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [communityUuid];
|
||||
}
|
||||
|
||||
class CreateSpaceEvent extends SpaceManagementEvent {
|
||||
final String name;
|
||||
final String icon;
|
||||
|
@ -56,13 +56,15 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
);
|
||||
if (selectedIndex != -1) {
|
||||
selectedCommunity = state.communities[selectedIndex];
|
||||
} else {
|
||||
selectedCommunity = null;
|
||||
selectedSpace = null;
|
||||
}
|
||||
|
||||
return LoadedSpaceView(
|
||||
communities: state.communities,
|
||||
selectedCommunity: selectedCommunity,
|
||||
selectedSpace: selectedSpace,
|
||||
products:state.products,
|
||||
products: state.products,
|
||||
onCommunitySelected: (community) {
|
||||
setState(() {
|
||||
selectedCommunity = community;
|
||||
|
@ -119,7 +119,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
return SpaceContainerWidget(
|
||||
index: index,
|
||||
onDoubleTap: () {
|
||||
print(spaces[index].toString());
|
||||
_showEditSpaceDialog(spaces[index]);
|
||||
},
|
||||
icon: spaces[index].icon ?? '',
|
||||
@ -209,12 +208,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
onPressed: () {
|
||||
showDeleteConfirmationDialog(context, () {
|
||||
// Handle the delete action here
|
||||
print("Delete confirmed");
|
||||
Navigator.of(context).pop(); // Close the dialog after confirming
|
||||
_onDelete();
|
||||
}, widget.selectedSpace != null);
|
||||
},
|
||||
icon: SvgPicture.asset(
|
||||
Assets.acFanAuto, // Path to your SVG asset
|
||||
Assets.delete, // Path to your SVG asset
|
||||
width: 18, // Adjust width as needed
|
||||
height: 18, // Adjust height as needed
|
||||
),
|
||||
@ -426,4 +425,13 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
communityUuid: communityUuid,
|
||||
));
|
||||
}
|
||||
|
||||
void _onDelete() {
|
||||
if (widget.selectedCommunity != null && widget.selectedCommunity?.uuid != null) {
|
||||
context.read<SpaceManagementBloc>().add(DeleteCommunityEvent(
|
||||
communityUuid: widget.selectedCommunity!.uuid,
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,5 +235,5 @@ class Assets {
|
||||
static const String garageDoor = 'assets/icons/garage_opener.svg';
|
||||
static const String doorSensor = 'assets/icons/door_sensor.svg';
|
||||
|
||||
static const String delete = 'assets/icons/delete_svg';
|
||||
static const String delete = 'assets/icons/delete.svg';
|
||||
}
|
||||
|
Reference in New Issue
Block a user