save only if there is a change or new space

This commit is contained in:
hannathkadher
2024-11-19 13:11:57 +04:00
parent 3147fc154f
commit 3a333188f8
3 changed files with 42 additions and 18 deletions

View File

@ -193,6 +193,9 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
void _updateNodePosition(SpaceModel node, Offset newPosition) {
setState(() {
node.position = newPosition;
if (node.status != SpaceStatus.newSpace) {
node.status = SpaceStatus.modified; // Mark as modified
}
if (node.position.dx >= canvasWidth - 200) {
canvasWidth += 200;
}
@ -244,6 +247,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
position: centerPosition,
isPrivate: false,
children: [],
status: SpaceStatus.newSpace,
);
if (parentIndex != null && direction != null) {
@ -330,14 +334,21 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
return;
}
// Prepare spaces and connections data
List<SpaceModel> spaceList = spaces;
List<SpaceModel> spacesToSave = spaces.where((space) {
return space.status == SpaceStatus.newSpace || space.status == SpaceStatus.modified;
}).toList();
if (spacesToSave.isEmpty) {
print("No new or modified spaces to save.");
return;
}
String communityUuid = widget.selectedCommunity!.uuid;
// Dispatch the save event
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
spaces: spaceList,
spaces: spacesToSave,
communityUuid: communityUuid,
));
}
}