Integrate CommunitiesTreeSelectionBloc into CreateSpaceButton to handle space selection upon successful space creation. Update community state in CommunitiesBloc to reflect new space addition, enhancing user experience and maintainability.

This commit is contained in:
Faris Armoush
2025-07-16 11:18:24 +03:00
parent 62f67f5a5f
commit 6ec972a520

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.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/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/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/space_details/presentation/helpers/space_details_dialog_helper.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/helpers/space_details_dialog_helper.dart';
import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/color_manager.dart';
@ -31,11 +32,17 @@ class _CreateSpaceButtonState extends State<CreateSpaceButton> {
communityUuid: widget.community.uuid, communityUuid: widget.community.uuid,
onSuccess: (updatedSpaceModel) { onSuccess: (updatedSpaceModel) {
final newCommunity = widget.community.copyWith( final newCommunity = widget.community.copyWith(
spaces: [updatedSpaceModel, ...widget.community.spaces], spaces: [...widget.community.spaces, updatedSpaceModel],
); );
context.read<CommunitiesBloc>().add( context.read<CommunitiesBloc>().add(
CommunitiesUpdateCommunity(newCommunity), CommunitiesUpdateCommunity(newCommunity),
); );
context.read<CommunitiesTreeSelectionBloc>().add(
SelectSpaceEvent(
space: updatedSpaceModel,
community: newCommunity,
),
);
}, },
), ),
child: MouseRegion( child: MouseRegion(