Refactor SpaceManagementPage to use StatefulWidget and initialize CommunitiesBloc in initState. Update CommunityStructureHeader to handle community updates and improve state management in CommunitiesTreeSelectionBloc with new event for community state updates.

This commit is contained in:
Faris Armoush
2025-07-14 10:27:22 +03:00
parent a409e34643
commit 7331c8440b
7 changed files with 189 additions and 20 deletions

View File

@ -42,6 +42,7 @@ abstract final class SpaceDetailsDialogHelper {
BuildContext context, {
required SpaceModel spaceModel,
required String communityUuid,
required void Function(SpaceDetailsModel updatedSpaceDetails)? onSuccess,
}) {
showDialog<void>(
context: context,
@ -60,7 +61,11 @@ abstract final class SpaceDetailsDialogHelper {
],
child: Builder(
builder: (context) => BlocListener<UpdateSpaceBloc, UpdateSpaceState>(
listener: _updateListener,
listener: (context, state) => _updateListener(
context,
state,
onSuccess,
),
child: SpaceDetailsDialog(
context: context,
title: const SelectableText('Edit Space'),
@ -81,17 +86,28 @@ abstract final class SpaceDetailsDialogHelper {
);
}
static void _updateListener(BuildContext context, UpdateSpaceState state) {
static void _updateListener(
BuildContext context,
UpdateSpaceState state,
void Function(SpaceDetailsModel updatedSpaceDetails)? onSuccess,
) {
return switch (state) {
UpdateSpaceInitial() => null,
UpdateSpaceLoading() => _onLoading(context),
UpdateSpaceSuccess(:final space) => _onUpdateSuccess(context, space),
UpdateSpaceSuccess(:final space) =>
_onUpdateSuccess(context, space, onSuccess),
UpdateSpaceFailure(:final errorMessage) => _onError(context, errorMessage),
};
}
static void _onUpdateSuccess(BuildContext context, SpaceDetailsModel space) {
static void _onUpdateSuccess(
BuildContext context,
SpaceDetailsModel space,
void Function(SpaceDetailsModel updatedSpaceDetails)? onSuccess,
) {
Navigator.of(context).pop();
Navigator.of(context).pop();
onSuccess?.call(space);
}
static void _onLoading(BuildContext context) {