mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
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.
This commit is contained in:
@ -15,7 +15,10 @@ abstract final class SpaceManagementCommunityDialogHelper {
|
||||
) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => EditCommunityDialog(community: community),
|
||||
builder: (_) => EditCommunityDialog(
|
||||
community: community,
|
||||
parentContext: context,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -120,11 +120,12 @@ class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||
CommunitiesUpdateCommunity event,
|
||||
Emitter<CommunitiesState> 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -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<CommunitiesBloc>().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<CommunitiesBloc>().add(
|
||||
CommunitiesUpdateCommunity(community),
|
||||
);
|
||||
parentContext.read<CommunitiesTreeSelectionBloc>().add(
|
||||
SelectCommunityEvent(community: community),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user