updated body for update space model

This commit is contained in:
hannathkadher
2025-03-06 11:41:36 +04:00
parent d2ff909bf2
commit fecab17cbe
7 changed files with 26 additions and 31 deletions

View File

@ -248,7 +248,7 @@ class CreateSpaceModelBloc
for (var tag in newSubspace.tags!) {
tagUpdates.add(TagModelUpdate(
action: Action.add,
uuid: tag.uuid == '' ? null : tag.uuid,
newTagUuid: tag.uuid == '' ? null : tag.uuid,
tag: tag.tag,
productUuid: tag.product?.uuid));
}
@ -315,7 +315,7 @@ class CreateSpaceModelBloc
tagUpdates.add(TagModelUpdate(
action: Action.add,
tag: newTag.tag,
uuid: newTag.uuid,
newTagUuid: newTag.uuid,
productUuid: newTag.product?.uuid,
));
}
@ -351,7 +351,7 @@ class CreateSpaceModelBloc
tagUpdates.add(TagModelUpdate(
action: Action.add,
tag: newTag.tag,
uuid: newTag.uuid == '' ? null : newTag.uuid,
newTagUuid: newTag.uuid == '' ? null : newTag.uuid,
productUuid: newTag.product?.uuid));
processedTags.add(newTag.tag);
}
@ -367,7 +367,8 @@ class CreateSpaceModelBloc
if (newTag != null) {
tagUpdates.add(TagModelUpdate(
action: Action.update,
uuid: newTag.uuid,
uuid: prevTag.uuid,
newTagUuid: newTag.uuid,
tag: newTag.tag,
));
} else {}

View File

@ -14,28 +14,23 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
required this.api,
required List<SpaceTemplateModel> initialSpaceModels,
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
log('Initial Space Models in: ${initialSpaceModels.map((e) => e.toJson()).toList()}');
on<CreateSpaceModel>(_onCreateSpaceModel);
on<UpdateSpaceModel>(_onUpdateSpaceModel);
on<DeleteSpaceModel>(_onDeleteSpaceModel);
}
Future<void> _onCreateSpaceModel(
CreateSpaceModel event, Emitter<SpaceModelState> emit) async {
Future<void> _onCreateSpaceModel(CreateSpaceModel event, Emitter<SpaceModelState> emit) async {
final currentState = state;
if (currentState is SpaceModelLoaded) {
try {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
final newSpaceModel = await api.getSpaceModel(
event.newSpaceModel.uuid ?? '', projectUuid);
final newSpaceModel = await api.getSpaceModel(event.newSpaceModel.uuid ?? '', projectUuid);
if (newSpaceModel != null) {
final updatedSpaceModels =
List<SpaceTemplateModel>.from(currentState.spaceModels)
..add(newSpaceModel);
final updatedSpaceModels = List<SpaceTemplateModel>.from(currentState.spaceModels)
..add(newSpaceModel);
emit(SpaceModelLoaded(spaceModels: updatedSpaceModels));
}
} catch (e) {
@ -44,15 +39,13 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
}
}
Future<void> _onUpdateSpaceModel(
UpdateSpaceModel event, Emitter<SpaceModelState> emit) async {
Future<void> _onUpdateSpaceModel(UpdateSpaceModel event, Emitter<SpaceModelState> emit) async {
final currentState = state;
if (currentState is SpaceModelLoaded) {
try {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
final newSpaceModel =
await api.getSpaceModel(event.spaceModelUuid, projectUuid);
final newSpaceModel = await api.getSpaceModel(event.spaceModelUuid, projectUuid);
if (newSpaceModel != null) {
final updatedSpaceModels = currentState.spaceModels.map((model) {
return model.uuid == event.spaceModelUuid ? newSpaceModel : model;
@ -65,16 +58,14 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
}
}
Future<void> _onDeleteSpaceModel(
DeleteSpaceModel event, Emitter<SpaceModelState> emit) async {
Future<void> _onDeleteSpaceModel(DeleteSpaceModel event, Emitter<SpaceModelState> emit) async {
final currentState = state;
if (currentState is SpaceModelLoaded) {
try {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
final deletedSuccessfully =
await api.deleteSpaceModel(event.spaceModelUuid, projectUuid);
final deletedSuccessfully = await api.deleteSpaceModel(event.spaceModelUuid, projectUuid);
if (deletedSuccessfully) {
final updatedSpaceModels = currentState.spaceModels