Refactor DuplicateSpaceService to return a list of SpaceModel objects instead of a single instance. Update related components including DuplicateSpaceSuccess state and DuplicateSpaceDialog to handle multiple spaces. Enhance CommunityStructureHeaderActionButtonsComposer to reflect these changes in the success callback.

This commit is contained in:
Faris Armoush
2025-07-23 12:42:23 +03:00
parent d21850edc8
commit 2077ef053f
5 changed files with 23 additions and 17 deletions

View File

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:flutter/material.dart'; 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/main_module/helpers/spaces_recursive_helper.dart'; import 'package:syncrow_web/pages/space_management_v2/main_module/helpers/spaces_recursive_helper.dart';
@ -53,8 +51,16 @@ class CommunityStructureHeaderActionButtonsComposer extends StatelessWidget {
initialName: space.spaceName, initialName: space.spaceName,
selectedSpaceUuid: space.uuid, selectedSpaceUuid: space.uuid,
selectedCommunityUuid: selectedCommunity.uuid, selectedCommunityUuid: selectedCommunity.uuid,
onSuccess: (space) { onSuccess: (spaces) {
log('space: $space'); final updatedCommunity = selectedCommunity.copyWith(
spaces: spaces,
);
context.read<CommunitiesBloc>().add(
CommunitiesUpdateCommunity(updatedCommunity),
);
context.read<CommunitiesTreeSelectionBloc>().add(
SelectCommunityEvent(community: updatedCommunity),
);
}, },
), ),
), ),

View File

@ -13,15 +13,17 @@ final class RemoteDuplicateSpaceService implements DuplicateSpaceService {
final HTTPService _httpService; final HTTPService _httpService;
@override @override
Future<SpaceModel> duplicateSpace(DuplicateSpaceParam param) async { Future<List<SpaceModel>> duplicateSpace(DuplicateSpaceParam param) async {
try { try {
final response = await _httpService.post( final response = await _httpService.post(
path: await _makeUrl(param), path: await _makeUrl(param),
body: param.toJson(), body: param.toJson(),
expectedResponseModel: (json) { expectedResponseModel: (json) {
final response = json as Map<String, dynamic>; final response = json as Map<String, dynamic>;
final data = response['data'] as Map<String, dynamic>; final data = response['data'] as List<dynamic>;
return SpaceModel.fromJson(data); return data
.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
.toList();
}, },
); );

View File

@ -2,5 +2,5 @@ import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain
import 'package:syncrow_web/pages/space_management_v2/modules/duplicate_space/domain/params/duplicate_space_param.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/duplicate_space/domain/params/duplicate_space_param.dart';
abstract interface class DuplicateSpaceService { abstract interface class DuplicateSpaceService {
Future<SpaceModel> duplicateSpace(DuplicateSpaceParam param); Future<List<SpaceModel>> duplicateSpace(DuplicateSpaceParam param);
} }

View File

@ -16,12 +16,12 @@ final class DuplicateSpaceLoading extends DuplicateSpaceState {
} }
final class DuplicateSpaceSuccess extends DuplicateSpaceState { final class DuplicateSpaceSuccess extends DuplicateSpaceState {
const DuplicateSpaceSuccess(this.space); const DuplicateSpaceSuccess(this.spaces);
final SpaceModel space; final List<SpaceModel> spaces;
@override @override
List<Object> get props => [space]; List<Object> get props => [spaces];
} }
final class DuplicateSpaceFailure extends DuplicateSpaceState { final class DuplicateSpaceFailure extends DuplicateSpaceState {

View File

@ -18,7 +18,7 @@ class DuplicateSpaceDialog extends StatelessWidget {
}); });
final String initialName; final String initialName;
final void Function(SpaceModel space) onSuccess; final void Function(List<SpaceModel> spaces) onSuccess;
final String selectedSpaceUuid; final String selectedSpaceUuid;
final String selectedCommunityUuid; final String selectedCommunityUuid;
@ -55,13 +55,11 @@ class DuplicateSpaceDialog extends StatelessWidget {
context.showFailureSnackbar(errorMessage); context.showFailureSnackbar(errorMessage);
break; break;
case DuplicateSpaceSuccess(:final space): case DuplicateSpaceSuccess(:final spaces):
onSuccess.call(space); onSuccess.call(spaces);
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pop(); Navigator.of(context).pop();
context.showSuccessSnackbar( context.showSuccessSnackbar('Space duplicated successfully');
'${space.spaceName} duplicated successfully',
);
break; break;
default: default: