diff --git a/lib/pages/spaces_management/bloc/space_management_bloc.dart b/lib/pages/spaces_management/bloc/space_management_bloc.dart index 3ff8216e..1f413bd8 100644 --- a/lib/pages/spaces_management/bloc/space_management_bloc.dart +++ b/lib/pages/spaces_management/bloc/space_management_bloc.dart @@ -19,6 +19,7 @@ class SpaceManagementBloc extends Bloc(_onCreateCommunity); on(_onSaveSpaces); on(_onFetchProducts); + on(_onCommunityDelete); } void _onFetchProducts( @@ -74,11 +75,29 @@ class SpaceManagementBloc extends Bloc 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 emit, ) { - // Handle space position update logic } void _onCreateCommunity( @@ -110,7 +129,6 @@ class SpaceManagementBloc extends Bloc emit, @@ -139,29 +157,26 @@ class SpaceManagementBloc extends Bloc get props => [communityUuid]; +} + class CreateSpaceEvent extends SpaceManagementEvent { final String name; final String icon; diff --git a/lib/pages/spaces_management/view/spaces_management_page.dart b/lib/pages/spaces_management/view/spaces_management_page.dart index 49c4b064..c2c9e8de 100644 --- a/lib/pages/spaces_management/view/spaces_management_page.dart +++ b/lib/pages/spaces_management/view/spaces_management_page.dart @@ -56,13 +56,15 @@ class SpaceManagementPageState extends State { ); 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; diff --git a/lib/pages/spaces_management/widgets/community_structure_widget.dart b/lib/pages/spaces_management/widgets/community_structure_widget.dart index dfb76bc3..97265ca1 100644 --- a/lib/pages/spaces_management/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_widget.dart @@ -119,7 +119,6 @@ class _CommunityStructureAreaState extends State { return SpaceContainerWidget( index: index, onDoubleTap: () { - print(spaces[index].toString()); _showEditSpaceDialog(spaces[index]); }, icon: spaces[index].icon ?? '', @@ -209,12 +208,12 @@ class _CommunityStructureAreaState extends State { 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 { communityUuid: communityUuid, )); } + + void _onDelete() { + if (widget.selectedCommunity != null && widget.selectedCommunity?.uuid != null) { + context.read().add(DeleteCommunityEvent( + communityUuid: widget.selectedCommunity!.uuid, + )); + + } + } } diff --git a/lib/utils/constants/assets.dart b/lib/utils/constants/assets.dart index 4c359771..d96ce0dc 100644 --- a/lib/utils/constants/assets.dart +++ b/lib/utils/constants/assets.dart @@ -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'; }