mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 20:12:27 +00:00
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:
@ -1,5 +1,3 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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,
|
||||
selectedSpaceUuid: space.uuid,
|
||||
selectedCommunityUuid: selectedCommunity.uuid,
|
||||
onSuccess: (space) {
|
||||
log('space: $space');
|
||||
onSuccess: (spaces) {
|
||||
final updatedCommunity = selectedCommunity.copyWith(
|
||||
spaces: spaces,
|
||||
);
|
||||
context.read<CommunitiesBloc>().add(
|
||||
CommunitiesUpdateCommunity(updatedCommunity),
|
||||
);
|
||||
context.read<CommunitiesTreeSelectionBloc>().add(
|
||||
SelectCommunityEvent(community: updatedCommunity),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -13,15 +13,17 @@ final class RemoteDuplicateSpaceService implements DuplicateSpaceService {
|
||||
final HTTPService _httpService;
|
||||
|
||||
@override
|
||||
Future<SpaceModel> duplicateSpace(DuplicateSpaceParam param) async {
|
||||
Future<List<SpaceModel>> duplicateSpace(DuplicateSpaceParam param) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: await _makeUrl(param),
|
||||
body: param.toJson(),
|
||||
expectedResponseModel: (json) {
|
||||
final response = json as Map<String, dynamic>;
|
||||
final data = response['data'] as Map<String, dynamic>;
|
||||
return SpaceModel.fromJson(data);
|
||||
final data = response['data'] as List<dynamic>;
|
||||
return data
|
||||
.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -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';
|
||||
|
||||
abstract interface class DuplicateSpaceService {
|
||||
Future<SpaceModel> duplicateSpace(DuplicateSpaceParam param);
|
||||
Future<List<SpaceModel>> duplicateSpace(DuplicateSpaceParam param);
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ final class DuplicateSpaceLoading extends DuplicateSpaceState {
|
||||
}
|
||||
|
||||
final class DuplicateSpaceSuccess extends DuplicateSpaceState {
|
||||
const DuplicateSpaceSuccess(this.space);
|
||||
const DuplicateSpaceSuccess(this.spaces);
|
||||
|
||||
final SpaceModel space;
|
||||
final List<SpaceModel> spaces;
|
||||
|
||||
@override
|
||||
List<Object> get props => [space];
|
||||
List<Object> get props => [spaces];
|
||||
}
|
||||
|
||||
final class DuplicateSpaceFailure extends DuplicateSpaceState {
|
||||
|
@ -18,7 +18,7 @@ class DuplicateSpaceDialog extends StatelessWidget {
|
||||
});
|
||||
|
||||
final String initialName;
|
||||
final void Function(SpaceModel space) onSuccess;
|
||||
final void Function(List<SpaceModel> spaces) onSuccess;
|
||||
final String selectedSpaceUuid;
|
||||
final String selectedCommunityUuid;
|
||||
|
||||
@ -55,13 +55,11 @@ class DuplicateSpaceDialog extends StatelessWidget {
|
||||
context.showFailureSnackbar(errorMessage);
|
||||
break;
|
||||
|
||||
case DuplicateSpaceSuccess(:final space):
|
||||
onSuccess.call(space);
|
||||
case DuplicateSpaceSuccess(:final spaces):
|
||||
onSuccess.call(spaces);
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
context.showSuccessSnackbar(
|
||||
'${space.spaceName} duplicated successfully',
|
||||
);
|
||||
context.showSuccessSnackbar('Space duplicated successfully');
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user