From 73de1e6ff9dc9e4cdad56647ba3feff257049205 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Sun, 6 Jul 2025 12:52:35 +0300 Subject: [PATCH] Enhance EditCommunityDialog: Refactor to accept parent context and streamline community update handling. Introduced a new method `_onUpdateCommunitySuccess` for improved readability and maintainability. Updated `SpaceManagementCommunityDialogHelper` to pass the parent context for better state management in the community update flow. --- ...ce_management_community_dialog_helper.dart | 5 ++- .../presentation/bloc/communities_bloc.dart | 7 ++-- .../presentation/edit_community_dialog.dart | 36 +++++++++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart b/lib/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart index 2446ae81..e1981208 100644 --- a/lib/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart +++ b/lib/pages/space_management_v2/main_module/shared/helpers/space_management_community_dialog_helper.dart @@ -15,7 +15,10 @@ abstract final class SpaceManagementCommunityDialogHelper { ) { showDialog( context: context, - builder: (_) => EditCommunityDialog(community: community), + builder: (_) => EditCommunityDialog( + community: community, + parentContext: context, + ), ); } diff --git a/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart b/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart index 1b4f10a1..245448ea 100644 --- a/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart +++ b/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart @@ -120,11 +120,12 @@ class CommunitiesBloc extends Bloc { CommunitiesUpdateCommunity event, Emitter emit, ) { + final updatedCommunities = state.communities + .map((e) => e.uuid == event.community.uuid ? event.community : e) + .toList(); emit( state.copyWith( - communities: state.communities - .map((e) => e.uuid == event.community.uuid ? event.community : e) - .toList(), + communities: updatedCommunities, ), ); } diff --git a/lib/pages/space_management_v2/modules/update_community/presentation/edit_community_dialog.dart b/lib/pages/space_management_v2/modules/update_community/presentation/edit_community_dialog.dart index e4c13f3c..b566c02a 100644 --- a/lib/pages/space_management_v2/modules/update_community/presentation/edit_community_dialog.dart +++ b/lib/pages/space_management_v2/modules/update_community/presentation/edit_community_dialog.dart @@ -4,14 +4,20 @@ import 'package:syncrow_web/pages/space_management_v2/main_module/shared/helpers import 'package:syncrow_web/pages/space_management_v2/main_module/shared/widgets/community_dialog.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/communities/presentation/communities_tree_selection_bloc/communities_tree_selection_bloc.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/update_community/data/services/remote_update_community_service.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/update_community/presentation/bloc/update_community_bloc.dart'; import 'package:syncrow_web/services/api/http_service.dart'; class EditCommunityDialog extends StatelessWidget { - const EditCommunityDialog({required this.community, super.key}); + const EditCommunityDialog({ + required this.community, + required this.parentContext, + super.key, + }); final CommunityModel community; + final BuildContext parentContext; @override Widget build(BuildContext context) { @@ -26,15 +32,7 @@ class EditCommunityDialog extends StatelessWidget { SpaceManagementCommunityDialogHelper.showLoadingDialog(context); break; case UpdateCommunitySuccess(:final community): - Navigator.of(context).pop(); - Navigator.of(context).pop(); - SpaceManagementCommunityDialogHelper.showSuccessSnackBar( - context, - '${community.name} community updated successfully', - ); - context.read().add( - CommunitiesUpdateCommunity(community), - ); + _onUpdateCommunitySuccess(context, community); break; case UpdateCommunityFailure(): Navigator.of(context).pop(); @@ -52,4 +50,22 @@ class EditCommunityDialog extends StatelessWidget { ), ); } + + void _onUpdateCommunitySuccess( + BuildContext context, + CommunityModel community, + ) { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + SpaceManagementCommunityDialogHelper.showSuccessSnackBar( + context, + '${community.name} community updated successfully', + ); + parentContext.read().add( + CommunitiesUpdateCommunity(community), + ); + parentContext.read().add( + SelectCommunityEvent(community: community), + ); + } }