= ({ userImage, userName, id, color, position, rotation, target }) => {
const { setSelectedUser } = useSelectedUserStore();
const { setCamMode } = useCamMode();
+ const { activeModule } = useModuleStore();
+ const { toggleView } = useToggleView();
return (
@@ -35,7 +38,7 @@ const CollabUserIcon: React.FC = ({ userImage, userName, id
id="live-user-button"
className="user-image-container"
onClick={() => {
- if (!position || !rotation || !target) return;
+ if (!position || !rotation || !target || toggleView || (activeModule !== "builder" && activeModule !== "simulation")) return;
// Set the selected user in the store
setSelectedUser({
id: id,
diff --git a/app/src/modules/builder/asset/responseHandler/useAssetResponseHandler.ts b/app/src/modules/collaboration/responseHandler/useAssetResponseHandler.ts
similarity index 87%
rename from app/src/modules/builder/asset/responseHandler/useAssetResponseHandler.ts
rename to app/src/modules/collaboration/responseHandler/useAssetResponseHandler.ts
index 82eefa3..75b93e8 100644
--- a/app/src/modules/builder/asset/responseHandler/useAssetResponseHandler.ts
+++ b/app/src/modules/collaboration/responseHandler/useAssetResponseHandler.ts
@@ -1,5 +1,5 @@
import { useCallback } from "react";
-import { useSceneContext } from "../../../scene/sceneContext";
+import { useSceneContext } from "../../scene/sceneContext";
function useAssetResponseHandler() {
const { assetStore } = useSceneContext();
@@ -24,13 +24,13 @@ function useAssetResponseHandler() {
}, []);
const duplicateAssetInScene = useCallback((modelUuid: string, callback?: () => void) => {
- console.log("Duplicating asset with id:", modelUuid);
+ console.log("Duplicating asset: ", modelUuid);
if (callback) callback();
}, []);
const pasteAssetToScene = useCallback((asset: Asset, callback?: () => void) => {
- console.log("Pasting asset:", asset);
+ console.log("Pasting asset: ", asset);
if (callback) callback();
}, []);
diff --git a/app/src/modules/collaboration/responseHandler/useWallAssetResponseHandler.ts b/app/src/modules/collaboration/responseHandler/useWallAssetResponseHandler.ts
new file mode 100644
index 0000000..e555f55
--- /dev/null
+++ b/app/src/modules/collaboration/responseHandler/useWallAssetResponseHandler.ts
@@ -0,0 +1,47 @@
+import { useCallback } from "react";
+import { useSceneContext } from "../../scene/sceneContext";
+
+function useWallAssetResponseHandler() {
+ const { wallAssetStore } = useSceneContext();
+ const { addWallAsset, updateWallAsset, removeWallAsset } = wallAssetStore();
+
+ const addWallAssetToScene = useCallback((asset: WallAsset, callback?: () => void) => {
+ addWallAsset(asset);
+
+ if (callback) callback();
+ }, []);
+
+ const updateWallAssetInScene = useCallback((asset: WallAsset, callback?: () => void) => {
+ updateWallAsset(asset.modelUuid, asset);
+
+ if (callback) callback();
+ }, []);
+
+ const removeWallAssetFromScene = useCallback((modelUuid: string, callback?: () => void) => {
+ removeWallAsset(modelUuid);
+
+ if (callback) callback();
+ }, []);
+
+ const duplicateWallAssetInScene = useCallback((modelUuid: string, callback?: () => void) => {
+ console.log("Duplicating wallAsset: ", modelUuid);
+
+ if (callback) callback();
+ }, []);
+
+ const pasteAssetWallToScene = useCallback((asset: WallAsset, callback?: () => void) => {
+ console.log("Pasting wallAsset: ", asset);
+
+ if (callback) callback();
+ }, []);
+
+ return {
+ addWallAssetToScene,
+ updateWallAssetInScene,
+ removeWallAssetFromScene,
+ duplicateWallAssetInScene,
+ pasteAssetWallToScene,
+ };
+}
+
+export default useWallAssetResponseHandler;
diff --git a/app/src/modules/collaboration/responseHandler/useWallResponseHandler.ts b/app/src/modules/collaboration/responseHandler/useWallResponseHandler.ts
new file mode 100644
index 0000000..52f3846
--- /dev/null
+++ b/app/src/modules/collaboration/responseHandler/useWallResponseHandler.ts
@@ -0,0 +1,47 @@
+import { useCallback } from "react";
+import { useSceneContext } from "../../scene/sceneContext";
+
+function useWallResponseHandler() {
+ const { wallStore } = useSceneContext();
+ const { addWall, updateWall, removeWall } = wallStore();
+
+ const addWallToScene = useCallback((wall: Wall, callback?: () => void) => {
+ addWall(wall);
+
+ if (callback) callback();
+ }, []);
+
+ const updateWallInScene = useCallback((wall: Wall, callback?: () => void) => {
+ updateWall(wall.wallUuid, wall);
+
+ if (callback) callback();
+ }, []);
+
+ const removeWallFromScene = useCallback((modelUuid: string, callback?: () => void) => {
+ removeWall(modelUuid);
+
+ if (callback) callback();
+ }, []);
+
+ const duplicateWallInScene = useCallback((modelUuid: string, callback?: () => void) => {
+ console.log("Duplicating wall: ", modelUuid);
+
+ if (callback) callback();
+ }, []);
+
+ const pasteAssetWallToScene = useCallback((wall: Wall, callback?: () => void) => {
+ console.log("Pasting wall: ", wall);
+
+ if (callback) callback();
+ }, []);
+
+ return {
+ addWallToScene,
+ updateWallInScene,
+ removeWallFromScene,
+ duplicateWallInScene,
+ pasteAssetWallToScene,
+ };
+}
+
+export default useWallResponseHandler;
diff --git a/app/src/modules/collaboration/socket/builderResponses.tsx b/app/src/modules/collaboration/socket/builderResponses.tsx
index 1d406d0..78f0529 100644
--- a/app/src/modules/collaboration/socket/builderResponses.tsx
+++ b/app/src/modules/collaboration/socket/builderResponses.tsx
@@ -1,13 +1,17 @@
import { useEffect } from "react";
-import { useSocketStore } from "../../../store/socket/useSocketStore";
-import useAssetResponseHandler from "../../builder/asset/responseHandler/useAssetResponseHandler";
import { useSceneContext } from "../../scene/sceneContext";
+import { useSocketStore } from "../../../store/socket/useSocketStore";
+import useAssetResponseHandler from "../responseHandler/useAssetResponseHandler";
+import useWallAssetResponseHandler from "../responseHandler/useWallAssetResponseHandler";
+import useWallResponseHandler from "../responseHandler/useWallResponseHandler";
function BuilderResponses() {
const { assetStore } = useSceneContext();
const { getAssetById } = assetStore();
const { builderSocket } = useSocketStore();
const { addAssetToScene, updateAssetInScene, removeAssetFromScene } = useAssetResponseHandler();
+ const { addWallAssetToScene, updateWallAssetInScene, removeWallAssetFromScene } = useWallAssetResponseHandler();
+ const { addWallToScene, updateWallInScene, removeWallFromScene } = useWallResponseHandler();
//#region Asset
useEffect(() => {
@@ -54,7 +58,7 @@ function BuilderResponses() {
});
} else {
removeAssetFromScene(data.data.modelUuid, () => {
- echo.error(`Error adding asset: ${data?.data?.modelName}`);
+ echo.error(`Error adding or updating asset: ${data?.data?.modelName}`);
});
}
});
@@ -158,15 +162,62 @@ function BuilderResponses() {
if (!builderSocket) return;
builderSocket.on("v1:wall-asset:response:add", (data: any) => {
- if (!data.message) return;
+ if (!data.message || !data.data) {
+ echo.error(`Error adding or updating wallAsset`);
+ return;
+ }
if (data.message === "WallAsset Created Successfully") {
+ const model: WallAsset = {
+ modelName: data.data.modelName,
+ modelUuid: data.data.modelUuid,
+ wallUuid: data.data.wallUuid,
+ wallAssetType: data.data.wallAssetType,
+ assetId: data.data.assetId,
+ position: data.data.position,
+ rotation: data.data.rotation,
+ isLocked: data.data.isLocked,
+ isVisible: data.data.isVisible,
+ opacity: data.data.opacity,
+ };
+
+ addWallAssetToScene(model, () => {
+ echo.log(`Added wallAsset: ${model.modelName}`);
+ });
} else if (data.message === "WallAsset Updated Successfully") {
+ const model: WallAsset = {
+ modelName: data.data.modelName,
+ modelUuid: data.data.modelUuid,
+ wallUuid: data.data.wallUuid,
+ wallAssetType: data.data.wallAssetType,
+ assetId: data.data.assetId,
+ position: data.data.position,
+ rotation: data.data.rotation,
+ isLocked: data.data.isLocked,
+ isVisible: data.data.isVisible,
+ opacity: data.data.opacity,
+ };
+
+ updateWallAssetInScene(model, () => {
+ echo.log(`Updated wallAsset: ${model.modelName}`);
+ });
+ } else {
+ removeWallAssetFromScene(data.data.modelUuid, () => {
+ echo.error(`Error adding or updating wallAsset: ${data?.data?.modelName}`);
+ });
}
});
builderSocket.on("v1:wall-asset:response:delete", (data: any) => {
- if (!data.message) return;
- if (data.message === "WallAsset Created Successfully") {
+ if (!data.message || !data.data) {
+ echo.error(`Error removing wallAsset`);
+ return;
+ }
+ if (data.message === "WallAsset Deleted Successfully") {
+ removeWallAssetFromScene(data.data.modelUuid, () => {
+ echo.log(`Removed wallAsset: ${data.data.modelName}`);
+ });
+ } else {
+ echo.error(`Error removing wallAsset: ${data?.data?.modelName}`);
}
});
@@ -184,15 +235,56 @@ function BuilderResponses() {
if (!builderSocket) return;
builderSocket.on("v1:model-Wall:response:add", (data: any) => {
- if (!data.message) return;
+ if (!data.message || !data.data) {
+ echo.error(`Error adding or updating wall`);
+ return;
+ }
if (data.message === "Wall Created Successfully") {
+ const wall: Wall = {
+ wallUuid: data.data.wallUuid,
+ points: data.data.points,
+ outsideMaterial: data.data.outsideMaterial,
+ insideMaterial: data.data.insideMaterial,
+ wallThickness: data.data.wallThickness,
+ wallHeight: data.data.wallHeight,
+ decals: data.data.decals,
+ };
+
+ addWallToScene(wall, () => {
+ echo.log(`Added wall: ${wall.wallUuid}`);
+ });
} else if (data.message === "Wall Updated Successfully") {
+ const wall: Wall = {
+ wallUuid: data.data.wallUuid,
+ points: data.data.points,
+ outsideMaterial: data.data.outsideMaterial,
+ insideMaterial: data.data.insideMaterial,
+ wallThickness: data.data.wallThickness,
+ wallHeight: data.data.wallHeight,
+ decals: data.data.decals,
+ };
+
+ updateWallInScene(wall, () => {
+ echo.log(`Updated wall: ${wall.wallUuid}`);
+ });
+ } else {
+ removeWallFromScene(data.data.wallUuid, () => {
+ echo.error(`Error adding or updating wall: ${data?.data?.wallUuid}`);
+ });
}
});
builderSocket.on("v1:model-Wall:response:delete", (data: any) => {
- if (!data.message) return;
+ if (!data.message || !data.data) {
+ echo.error(`Error deleting wall`);
+ return;
+ }
if (data.message === "Wall Deleted Successfully") {
+ removeWallFromScene(data.data.wallUuid, () => {
+ echo.log(`Removed wall: ${data.data.wallUuid}`);
+ });
+ } else {
+ echo.error(`Error removing wall: ${data?.data?.wallUuid}`);
}
});
@@ -262,7 +354,6 @@ function BuilderResponses() {
if (!builderSocket) return;
builderSocket.on("v1:zone:response:updates", (data: any) => {
- console.log("data: ", data);
if (!data.message) return;
if (data.message === "zone created successfully") {
} else if (data.message === "zone updated") {
@@ -270,7 +361,6 @@ function BuilderResponses() {
});
builderSocket.on("v1:zone:response:delete", (data: any) => {
- console.log("data: ", data);
if (!data.message) return;
if (data.message === "zone deleted created successfully") {
}
diff --git a/app/src/modules/scene/controls/selectionControls/selection2D/moveControls2D.tsx b/app/src/modules/scene/controls/selectionControls/selection2D/moveControls2D.tsx
index c5f0156..28873b1 100644
--- a/app/src/modules/scene/controls/selectionControls/selection2D/moveControls2D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection2D/moveControls2D.tsx
@@ -1,14 +1,16 @@
import * as THREE from "three";
+import { useParams } from "react-router-dom";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useFrame, useThree } from "@react-three/fiber";
import { useToggleView, useToolMode } from "../../../../../store/builder/store";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModifierKeys";
-import { useParams } from "react-router-dom";
import { getUserData } from "../../../../../functions/getUserData";
import { useSceneContext } from "../../../sceneContext";
import { useSelectedPoints } from "../../../../../store/simulation/useSimulationStore";
import useModuleStore from "../../../../../store/ui/useModuleStore";
+import useWallAssetResponseHandler from "../../../../collaboration/responseHandler/useWallAssetResponseHandler";
+import useWallResponseHandler from "../../../../collaboration/responseHandler/useWallResponseHandler";
import { calculateAssetTransformationOnWall } from "../../../../builder/wallAsset/Instances/Instance/functions/calculateAssetTransformationOnWall";
import { upsertAisleApi } from "../../../../../services/factoryBuilder/aisle/upsertAisleApi";
@@ -29,7 +31,9 @@ function MoveControls2D({ movedObjects, setMovedObjects, pastedObjects, setPaste
const { projectId } = useParams();
const { aisleStore, wallStore, floorStore, zoneStore, undoRedo2DStore, wallAssetStore, versionStore } = useSceneContext();
const { selectedVersion } = versionStore();
- const { getWallAssetsByWall, updateWallAsset } = wallAssetStore();
+ const { getWallAssetsByWall } = wallAssetStore();
+ const { updateWallAssetInScene } = useWallAssetResponseHandler();
+ const { updateWallInScene } = useWallResponseHandler();
const { push2D } = undoRedo2DStore();
const { setPosition: setAislePosition, getAislesByPointId, getAisleById } = aisleStore();
const { setPosition: setWallPosition, getWallsByPointId, getWallById } = wallStore();
@@ -319,7 +323,23 @@ function MoveControls2D({ movedObjects, setMovedObjects, pastedObjects, setPaste
if (!builderSocket?.connected) {
// API
- upsertWallApi(projectId, selectedVersion?.versionId || "", updatedWall);
+ upsertWallApi(projectId, selectedVersion?.versionId || "", updatedWall)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error updating wall`);
+ return;
+ }
+ if (data.message === "Wall Updated Successfully") {
+ updateWallInScene(updatedWall, () => {
+ echo.log(`Updated wall: ${updatedWall.wallUuid}`);
+ });
+ } else {
+ echo.error(`Error updating wall: ${updatedWall.wallUuid}`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error updating wall: ${updatedWall.wallUuid}`);
+ });
} else {
// SOCKET
@@ -442,15 +462,26 @@ function MoveControls2D({ movedObjects, setMovedObjects, pastedObjects, setPaste
wallAssetUpdates.filter((wallAssets, index, self) => index === self.findIndex((w) => w.modelUuid === wallAssets.modelUuid));
wallAssetUpdates.forEach((updatedWallAsset) => {
if (projectId && updatedWallAsset) {
- updateWallAsset(updatedWallAsset.modelUuid, {
- position: updatedWallAsset.position,
- rotation: updatedWallAsset.rotation,
- });
-
if (!builderSocket?.connected) {
// API
- upsertWallAssetApi(projectId, selectedVersion?.versionId || "", updatedWallAsset);
+ upsertWallAssetApi(projectId, selectedVersion?.versionId || "", updatedWallAsset)
+ .then((data) => {
+ if (!data.message) {
+ echo.error(`Error updating wallAsset ${updatedWallAsset.modelName} on the wall`);
+ return;
+ }
+ if (data.message === "WallAsset Updated Successfully" && data.data) {
+ updateWallAssetInScene(updatedWallAsset, () => {
+ echo.log(`Updated wallAsset: ${updatedWallAsset.modelUuid}`);
+ });
+ } else {
+ echo.error(`Error updating wallAsset ${updatedWallAsset.modelName} on the wall`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error updating wallAsset ${updatedWallAsset.modelName} on the wall`);
+ });
} else {
// SOCKET
diff --git a/app/src/modules/scene/controls/selectionControls/selection2D/selectionControls2D.tsx b/app/src/modules/scene/controls/selectionControls/selection2D/selectionControls2D.tsx
index 3daf5fe..f6848f1 100644
--- a/app/src/modules/scene/controls/selectionControls/selection2D/selectionControls2D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection2D/selectionControls2D.tsx
@@ -12,6 +12,8 @@ import { useToggleView, useToolMode } from "../../../../../store/builder/store";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
import { useSelectedPoints } from "../../../../../store/simulation/useSimulationStore";
import { useBuilderStore } from "../../../../../store/builder/useBuilderStore";
+import useWallAssetResponseHandler from "../../../../collaboration/responseHandler/useWallAssetResponseHandler";
+import useWallResponseHandler from "../../../../collaboration/responseHandler/useWallResponseHandler";
import MoveControls2D from "./moveControls2D";
import { deleteAisleApi } from "../../../../../services/factoryBuilder/aisle/deleteAisleApi";
@@ -39,10 +41,12 @@ const SelectionControls2D: React.FC = () => {
const { hoveredLine, hoveredPoint } = useBuilderStore();
const { aisleStore, wallStore, floorStore, zoneStore, undoRedo2DStore, wallAssetStore, versionStore } = useSceneContext();
const { selectedVersion } = versionStore();
- const { getWallAssetsByWall, removeWallAsset } = wallAssetStore();
+ const { getWallAssetsByWall } = wallAssetStore();
+ const { removeWallAssetFromScene } = useWallAssetResponseHandler();
+ const { removeWallFromScene } = useWallResponseHandler();
const { push2D } = undoRedo2DStore();
const { removePoint: removeAislePoint } = aisleStore();
- const { removePoint: removeWallPoint } = wallStore();
+ const { peekRemovePoint: peekRemoveWallPoint } = wallStore();
const { removePoint: removeFloorPoint, getFloorsByPointId, getFloorById } = floorStore();
const { removePoint: removeZonePoint, getZonesByPointId, getZoneById } = zoneStore();
@@ -271,19 +275,33 @@ const SelectionControls2D: React.FC = () => {
}
}
if (point.pointType === "Wall") {
- const removedWalls = removeWallPoint(point.pointUuid);
+ const removedWalls = peekRemoveWallPoint(point.pointUuid);
if (removedWalls.length > 0) {
removedWalls.forEach((wall) => {
const assetsOnWall = getWallAssetsByWall(wall.wallUuid);
assetsOnWall.forEach((asset) => {
if (projectId && asset) {
- removeWallAsset(asset.modelUuid);
-
if (!builderSocket?.connected) {
// API
- deleteWallAssetApi(projectId, selectedVersion?.versionId || "", asset.modelUuid, asset.wallUuid);
+ deleteWallAssetApi(projectId, selectedVersion?.versionId || "", asset.modelUuid, asset.wallUuid)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error removing wallAsset from wall`);
+ return;
+ }
+ if (data.message === "WallAsset Deleted Successfully") {
+ removeWallAssetFromScene(asset.modelUuid, () => {
+ echo.log(`Removed wallAsset: ${asset.modelName} along with wall`);
+ });
+ } else {
+ echo.error(`Error removing wallAsset: ${asset.modelName} from wall`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error removing wallAsset: ${asset.modelName}`);
+ });
} else {
// SOCKET
@@ -305,7 +323,23 @@ const SelectionControls2D: React.FC = () => {
if (!builderSocket?.connected) {
// API
- deleteWallApi(projectId, selectedVersion?.versionId || "", wall.wallUuid);
+ deleteWallApi(projectId, selectedVersion?.versionId || "", wall.wallUuid)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error removing wall`);
+ return;
+ }
+ if (data.message === "Wall Deleted Successfully") {
+ removeWallFromScene(wall.wallUuid, () => {
+ echo.log(`Removed wall: ${wall.wallUuid}`);
+ });
+ } else {
+ echo.error(`Error removing wall: ${wall.wallUuid}`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error removing wall: ${wall.wallUuid}`);
+ });
} else {
// SOCKET
diff --git a/app/src/modules/scene/controls/selectionControls/selection3D/copyPasteControls3D.tsx b/app/src/modules/scene/controls/selectionControls/selection3D/copyPasteControls3D.tsx
index 5e0c52e..79103ec 100644
--- a/app/src/modules/scene/controls/selectionControls/selection3D/copyPasteControls3D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection3D/copyPasteControls3D.tsx
@@ -9,7 +9,7 @@ import { useSocketStore } from "../../../../../store/socket/useSocketStore";
import { useContextActionStore, useToggleView } from "../../../../../store/builder/store";
import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModifierKeys";
import { getUserData } from "../../../../../functions/getUserData";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { setAssetsApi } from "../../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
diff --git a/app/src/modules/scene/controls/selectionControls/selection3D/duplicationControls3D.tsx b/app/src/modules/scene/controls/selectionControls/selection3D/duplicationControls3D.tsx
index 271566d..1c02e62 100644
--- a/app/src/modules/scene/controls/selectionControls/selection3D/duplicationControls3D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection3D/duplicationControls3D.tsx
@@ -10,7 +10,7 @@ import { useContextActionStore, useToggleView } from "../../../../../store/build
import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModifierKeys";
import { getUserData } from "../../../../../functions/getUserData";
import { handleAssetPositionSnap } from "./functions/handleAssetPositionSnap";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { setAssetsApi } from "../../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
diff --git a/app/src/modules/scene/controls/selectionControls/selection3D/moveControls3D.tsx b/app/src/modules/scene/controls/selectionControls/selection3D/moveControls3D.tsx
index ced7fa9..779de9c 100644
--- a/app/src/modules/scene/controls/selectionControls/selection3D/moveControls3D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection3D/moveControls3D.tsx
@@ -11,7 +11,7 @@ import { handleAssetPositionSnap } from "./functions/handleAssetPositionSnap";
import DistanceFindingControls from "./distanceFindingControls";
import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModifierKeys";
import { getUserData } from "../../../../../functions/getUserData";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { upsertProductOrEventApi } from "../../../../../services/simulation/products/UpsertProductOrEventApi";
import { setAssetsApi } from "../../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
diff --git a/app/src/modules/scene/controls/selectionControls/selection3D/rotateControls3D.tsx b/app/src/modules/scene/controls/selectionControls/selection3D/rotateControls3D.tsx
index 87a524e..9be2e2c 100644
--- a/app/src/modules/scene/controls/selectionControls/selection3D/rotateControls3D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection3D/rotateControls3D.tsx
@@ -11,7 +11,7 @@ import { useSceneContext } from "../../../sceneContext";
import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModifierKeys";
import { handleAssetRotationSnap } from "./functions/handleAssetRotationSnap";
import useModuleStore from "../../../../../store/ui/useModuleStore";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { setAssetsApi } from "../../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
diff --git a/app/src/modules/scene/controls/selectionControls/selection3D/selectionControls3D.tsx b/app/src/modules/scene/controls/selectionControls/selection3D/selectionControls3D.tsx
index e7e5051..4c84035 100644
--- a/app/src/modules/scene/controls/selectionControls/selection3D/selectionControls3D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection3D/selectionControls3D.tsx
@@ -19,7 +19,7 @@ import TransformControls3D from "./transformControls3D";
import { useBuilderStore } from "../../../../../store/builder/useBuilderStore";
import { deleteFloorAssetApi } from "../../../../../services/factoryBuilder/asset/floorAsset/deleteFloorAssetApi";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
const SelectionControls3D: React.FC = () => {
const { camera, controls, gl, scene, raycaster, pointer } = useThree();
diff --git a/app/src/modules/scene/controls/selectionControls/selection3D/transformControls3D.tsx b/app/src/modules/scene/controls/selectionControls/selection3D/transformControls3D.tsx
index 43e37ab..8c1d971 100644
--- a/app/src/modules/scene/controls/selectionControls/selection3D/transformControls3D.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selection3D/transformControls3D.tsx
@@ -6,7 +6,7 @@ import { useRef, useEffect, useState, useCallback } from "react";
import { useToolMode } from "../../../../../store/builder/store";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
import { useSceneContext } from "../../../sceneContext";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { getUserData } from "../../../../../functions/getUserData";
import { upsertProductOrEventApi } from "../../../../../services/simulation/products/UpsertProductOrEventApi";
diff --git a/app/src/modules/scene/controls/transformControls/transformControls.tsx b/app/src/modules/scene/controls/transformControls/transformControls.tsx
index d16b078..233fd5f 100644
--- a/app/src/modules/scene/controls/transformControls/transformControls.tsx
+++ b/app/src/modules/scene/controls/transformControls/transformControls.tsx
@@ -8,7 +8,7 @@ import { useSceneContext } from "../../sceneContext";
import { useObjectPosition, useObjectRotation, useActiveTool } from "../../../../store/builder/store";
import { useSocketStore } from "../../../../store/socket/useSocketStore";
import { useBuilderStore } from "../../../../store/builder/useBuilderStore";
-import useAssetResponseHandler from "../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../collaboration/responseHandler/useAssetResponseHandler";
import { detectModifierKeys } from "../../../../utils/shortcutkeys/detectModifierKeys";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
diff --git a/app/src/modules/scene/controls/undoRedoControls/handlers/use2DRedoHandler.ts b/app/src/modules/scene/controls/undoRedoControls/handlers/use2DRedoHandler.ts
index 508414f..da7c569 100644
--- a/app/src/modules/scene/controls/undoRedoControls/handlers/use2DRedoHandler.ts
+++ b/app/src/modules/scene/controls/undoRedoControls/handlers/use2DRedoHandler.ts
@@ -2,6 +2,7 @@ import { useParams } from "react-router-dom";
import { getUserData } from "../../../../../functions/getUserData";
import { useSceneContext } from "../../../sceneContext";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
+import useWallResponseHandler from "../../../../collaboration/responseHandler/useWallResponseHandler";
import { upsertWallApi } from "../../../../../services/factoryBuilder/wall/upsertWallApi";
import { deleteWallApi } from "../../../../../services/factoryBuilder/wall/deleteWallApi";
@@ -16,9 +17,9 @@ import { upsertAisleApi } from "../../../../../services/factoryBuilder/aisle/ups
import { deleteAisleApi } from "../../../../../services/factoryBuilder/aisle/deleteAisleApi";
function use2DRedoHandler() {
- const { undoRedo2DStore, wallStore, floorStore, zoneStore, aisleStore, versionStore } = useSceneContext();
+ const { undoRedo2DStore, floorStore, zoneStore, aisleStore, versionStore } = useSceneContext();
const { redo2D, peekRedo2D } = undoRedo2DStore();
- const { addWall, removeWall, updateWall } = wallStore();
+ const { addWallToScene, removeWallFromScene, updateWallInScene } = useWallResponseHandler();
const { addFloor, removeFloor, updateFloor } = floorStore();
const { addZone, removeZone, updateZone } = zoneStore();
const { addAisle, removeAisle, updateAisle } = aisleStore();
@@ -119,12 +120,27 @@ function use2DRedoHandler() {
};
const createWallFromBackend = (wallData: Wall) => {
- addWall(wallData);
if (projectId) {
if (!builderSocket?.connected) {
// API
- upsertWallApi(projectId, selectedVersion?.versionId || "", wallData);
+ upsertWallApi(projectId, selectedVersion?.versionId || "", wallData)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error adding wall`);
+ return;
+ }
+ if (data.message === "Wall Created Successfully") {
+ addWallToScene(wallData, () => {
+ echo.log(`Added wall: ${wallData.wallUuid}`);
+ });
+ } else {
+ echo.error(`Error adding wall: ${wallData.wallUuid}`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error adding wall: ${wallData.wallUuid}`);
+ });
} else {
// SOCKET
@@ -142,12 +158,27 @@ function use2DRedoHandler() {
};
const removeWallFromBackend = (wallUuid: string) => {
- removeWall(wallUuid);
if (projectId) {
if (!builderSocket?.connected) {
// API
- deleteWallApi(projectId, selectedVersion?.versionId || "", wallUuid);
+ deleteWallApi(projectId, selectedVersion?.versionId || "", wallUuid)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error removing wall`);
+ return;
+ }
+ if (data.message === "Wall Deleted Successfully") {
+ removeWallFromScene(wallUuid, () => {
+ echo.log(`Removed wall: ${wallUuid}`);
+ });
+ } else {
+ echo.error(`Error removing wall: ${wallUuid}`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error removing wall: ${wallUuid}`);
+ });
} else {
// SOCKET
@@ -165,12 +196,25 @@ function use2DRedoHandler() {
};
const updateWallFromBackend = (wallUuid: string, updatedData: Wall) => {
- updateWall(wallUuid, updatedData);
if (projectId) {
if (!builderSocket?.connected) {
// API
- upsertWallApi(projectId, selectedVersion?.versionId || "", updatedData);
+ upsertWallApi(projectId, selectedVersion?.versionId || "", updatedData)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error updating wall`);
+ return;
+ }
+ if (data.message === "Wall Updated Successfully") {
+ updateWallInScene(updatedData, () => {
+ echo.log(`Updated wall: ${updatedData.wallUuid}`);
+ });
+ }
+ })
+ .catch(() => {
+ echo.error(`Error updating wall: ${updatedData.wallUuid}`);
+ });
} else {
// SOCKET
diff --git a/app/src/modules/scene/controls/undoRedoControls/handlers/use2DUndoHandler.ts b/app/src/modules/scene/controls/undoRedoControls/handlers/use2DUndoHandler.ts
index d0e723a..2353e64 100644
--- a/app/src/modules/scene/controls/undoRedoControls/handlers/use2DUndoHandler.ts
+++ b/app/src/modules/scene/controls/undoRedoControls/handlers/use2DUndoHandler.ts
@@ -2,6 +2,7 @@ import { useParams } from "react-router-dom";
import { getUserData } from "../../../../../functions/getUserData";
import { useSceneContext } from "../../../sceneContext";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
+import useWallResponseHandler from "../../../../collaboration/responseHandler/useWallResponseHandler";
import { upsertWallApi } from "../../../../../services/factoryBuilder/wall/upsertWallApi";
import { deleteWallApi } from "../../../../../services/factoryBuilder/wall/deleteWallApi";
@@ -16,9 +17,9 @@ import { upsertAisleApi } from "../../../../../services/factoryBuilder/aisle/ups
import { deleteAisleApi } from "../../../../../services/factoryBuilder/aisle/deleteAisleApi";
function use2DUndoHandler() {
- const { undoRedo2DStore, wallStore, floorStore, zoneStore, aisleStore, versionStore } = useSceneContext();
+ const { undoRedo2DStore, floorStore, zoneStore, aisleStore, versionStore } = useSceneContext();
const { undo2D, peekUndo2D } = undoRedo2DStore();
- const { addWall, removeWall, updateWall } = wallStore();
+ const { addWallToScene, removeWallFromScene, updateWallInScene } = useWallResponseHandler();
const { addFloor, removeFloor, updateFloor } = floorStore();
const { addZone, removeZone, updateZone } = zoneStore();
const { addAisle, removeAisle, updateAisle } = aisleStore();
@@ -118,12 +119,27 @@ function use2DUndoHandler() {
};
const createWallToBackend = (wallData: Wall) => {
- addWall(wallData);
if (projectId) {
if (!builderSocket?.connected) {
// API
- upsertWallApi(projectId, selectedVersion?.versionId || "", wallData);
+ upsertWallApi(projectId, selectedVersion?.versionId || "", wallData)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error adding wall`);
+ return;
+ }
+ if (data.message === "Wall Created Successfully") {
+ addWallToScene(wallData, () => {
+ echo.log(`Added wall: ${wallData.wallUuid}`);
+ });
+ } else {
+ echo.error(`Error adding wall: ${wallData.wallUuid}`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error adding wall: ${wallData.wallUuid}`);
+ });
} else {
// SOCKET
@@ -136,17 +152,33 @@ function use2DUndoHandler() {
};
builderSocket.emit("v1:model-Wall:add", data);
+ console.log('data: ', data);
}
}
};
const removeWallToBackend = (wallUuid: string) => {
- removeWall(wallUuid);
if (projectId) {
if (!builderSocket?.connected) {
// API
- deleteWallApi(projectId, selectedVersion?.versionId || "", wallUuid);
+ deleteWallApi(projectId, selectedVersion?.versionId || "", wallUuid)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error removing wall`);
+ return;
+ }
+ if (data.message === "Wall Deleted Successfully") {
+ removeWallFromScene(wallUuid, () => {
+ echo.log(`Removed wall: ${wallUuid}`);
+ });
+ } else {
+ echo.error(`Error removing wall: ${wallUuid}`);
+ }
+ })
+ .catch(() => {
+ echo.error(`Error removing wall: ${wallUuid}`);
+ });
} else {
// SOCKET
@@ -164,12 +196,25 @@ function use2DUndoHandler() {
};
const updateWallToBackend = (wallUuid: string, updatedData: Wall) => {
- updateWall(wallUuid, updatedData);
if (projectId) {
if (!builderSocket?.connected) {
// API
- upsertWallApi(projectId, selectedVersion?.versionId || "", updatedData);
+ upsertWallApi(projectId, selectedVersion?.versionId || "", updatedData)
+ .then((data) => {
+ if (!data.message || !data.data) {
+ echo.error(`Error updating wall`);
+ return;
+ }
+ if (data.message === "Wall Updated Successfully") {
+ updateWallInScene(updatedData, () => {
+ echo.log(`Updated wall: ${updatedData.wallUuid}`);
+ });
+ }
+ })
+ .catch(() => {
+ echo.error(`Error updating wall: ${updatedData.wallUuid}`);
+ });
} else {
// SOCKET
diff --git a/app/src/modules/scene/controls/undoRedoControls/handlers/use3DRedoHandler.ts b/app/src/modules/scene/controls/undoRedoControls/handlers/use3DRedoHandler.ts
index 60b7eab..2d2c019 100644
--- a/app/src/modules/scene/controls/undoRedoControls/handlers/use3DRedoHandler.ts
+++ b/app/src/modules/scene/controls/undoRedoControls/handlers/use3DRedoHandler.ts
@@ -2,7 +2,7 @@ import { useParams } from "react-router-dom";
import { getUserData } from "../../../../../functions/getUserData";
import { useSceneContext } from "../../../sceneContext";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { upsertProductOrEventApi } from "../../../../../services/simulation/products/UpsertProductOrEventApi";
@@ -13,7 +13,7 @@ function use3DRedoHandler() {
const { undoRedo3DStore, productStore, eventStore, versionStore } = useSceneContext();
const { deleteEvent, selectedProduct } = productStore();
const { addEvent, removeEvent } = eventStore();
- const { addAssetToScene, removeAssetFromScene, updateAssetInScene } = useAssetResponseHandler();
+ const { addAssetToScene, removeAssetFromScene } = useAssetResponseHandler();
const { redo3D, peekRedo3D } = undoRedo3DStore();
const { selectedVersion } = versionStore();
const { userId, organization } = getUserData();
diff --git a/app/src/modules/scene/controls/undoRedoControls/handlers/use3DUndoHandler.ts b/app/src/modules/scene/controls/undoRedoControls/handlers/use3DUndoHandler.ts
index fa6b213..c6a304c 100644
--- a/app/src/modules/scene/controls/undoRedoControls/handlers/use3DUndoHandler.ts
+++ b/app/src/modules/scene/controls/undoRedoControls/handlers/use3DUndoHandler.ts
@@ -2,7 +2,7 @@ import { useParams } from "react-router-dom";
import { getUserData } from "../../../../../functions/getUserData";
import { useSceneContext } from "../../../sceneContext";
import { useSocketStore } from "../../../../../store/socket/useSocketStore";
-import useAssetResponseHandler from "../../../../builder/asset/responseHandler/useAssetResponseHandler";
+import useAssetResponseHandler from "../../../../collaboration/responseHandler/useAssetResponseHandler";
import { upsertProductOrEventApi } from "../../../../../services/simulation/products/UpsertProductOrEventApi";
diff --git a/app/src/services/simulation/comparison/validateSimulationDataApi.ts b/app/src/services/simulation/comparison/validateSimulationDataApi.ts
index 4323e35..4dcfe38 100644
--- a/app/src/services/simulation/comparison/validateSimulationDataApi.ts
+++ b/app/src/services/simulation/comparison/validateSimulationDataApi.ts
@@ -1,4 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
+
export const validateSimulationDataApi = async (data: any) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/V1/ValidateSimulated`, {
diff --git a/app/src/store/builder/useWallStore.ts b/app/src/store/builder/useWallStore.ts
index 705e611..74afdbe 100644
--- a/app/src/store/builder/useWallStore.ts
+++ b/app/src/store/builder/useWallStore.ts
@@ -1,30 +1,36 @@
-import { create } from 'zustand';
-import { immer } from 'zustand/middleware/immer';
+import { create } from "zustand";
+import { immer } from "zustand/middleware/immer";
interface WallStore {
walls: Wall[];
setWalls: (walls: Wall[]) => void;
addWall: (wall: Wall) => void;
- updateWall: (uuid: string, updated: Partial) => Wall | undefined;
- removeWall: (uuid: string) => void;
+ updateWall: (wallUuid: string, updated: Partial) => Wall | undefined;
+ peekUpdateWall: (wallUuid: string, updated: Partial) => Wall | undefined;
+ removeWall: (wallUuid: string) => void;
clearWalls: () => void;
removeWallByPoints: (Points: [Point, Point]) => Wall | undefined;
+ peekRemoveWallByPoints: (points: [Point, Point]) => Wall | undefined;
addDecal: (wallUuid: string, decal: Decal) => Decal | undefined;
+ peekAddDecal: (wallUuid: string, decal: Decal) => Wall | undefined;
updateDecal: (decalUuid: string, decal: Partial) => Wall | undefined;
+ peekUpdateDecal: (decalUuid: string, decal: Partial) => Wall | undefined;
removeDecal: (decalUuid: string) => Wall | undefined;
updateDecalPosition: (decalUuid: string, position: [number, number, number]) => Wall | undefined;
updateDecalRotation: (decalUuid: string, rotation: number) => void;
updateDecalScale: (decalUuid: string, scale: number) => void;
removePoint: (pointUuid: string) => Wall[];
+ peekRemovePoint: (pointUuid: string) => Wall[];
+
setPosition: (pointUuid: string, position: [number, number, number]) => Wall[] | [];
setLayer: (pointUuid: string, layer: number) => void;
- getWallById: (uuid: string) => Wall | undefined;
- getWallsByPointId: (uuid: string) => Wall[] | [];
+ getWallById: (wallUuid: string) => Wall | undefined;
+ getWallsByPointId: (wallUuid: string) => Wall[] | [];
getWallByPoints: (points: Point[]) => Wall | undefined;
- getWallPointById: (uuid: string) => Point | undefined;
- getConnectedPoints: (uuid: string) => Point[];
+ getWallPointById: (wallUuid: string) => Point | undefined;
+ getConnectedPoints: (wallUuid: string) => Point[];
getConnectedWallsByWallId: (wallUuid: string, skipSelf: boolean) => Wall[];
}
@@ -33,18 +39,20 @@ export const createWallStore = () => {
immer((set, get) => ({
walls: [],
- setWalls: (walls) => set((state) => {
- state.walls = walls;
- }),
+ setWalls: (walls) =>
+ set((state) => {
+ state.walls = walls;
+ }),
- addWall: (wall) => set((state) => {
- state.walls.push(wall);
- }),
+ addWall: (wall) =>
+ set((state) => {
+ state.walls.push(wall);
+ }),
- updateWall: (uuid, updated) => {
+ updateWall: (wallUuid, updated) => {
let updatedWall: Wall | undefined;
set((state) => {
- const wall = state.walls.find(w => w.wallUuid === uuid);
+ const wall = state.walls.find((w) => w.wallUuid === wallUuid);
if (wall) {
Object.assign(wall, updated);
updatedWall = JSON.parse(JSON.stringify(wall));
@@ -53,14 +61,25 @@ export const createWallStore = () => {
return updatedWall;
},
- removeWall: (uuid) => set((state) => {
- state.walls = state.walls.filter(w => w.wallUuid !== uuid);
- }),
+ peekUpdateWall: (wallUuid, updated) => {
+ const wall = get().walls.find((w) => w.wallUuid === wallUuid);
+ if (!wall) return undefined;
+
+ const clonedWall: Wall = JSON.parse(JSON.stringify(wall));
+ Object.assign(clonedWall, updated);
+
+ return clonedWall;
+ },
+
+ removeWall: (wallUuid) =>
+ set((state) => {
+ state.walls = state.walls.filter((w) => w.wallUuid !== wallUuid);
+ }),
clearWalls: () => {
set((state) => {
state.walls = [];
- })
+ });
},
removeWallByPoints: (points) => {
@@ -68,8 +87,8 @@ export const createWallStore = () => {
const [pointA, pointB] = points;
set((state) => {
- state.walls = state.walls.filter(wall => {
- const wallPoints = wall.points.map(p => p.pointUuid);
+ state.walls = state.walls.filter((wall) => {
+ const wallPoints = wall.points.map((p) => p.pointUuid);
const hasBothPoints = wallPoints.includes(pointA.pointUuid) && wallPoints.includes(pointB.pointUuid);
if (hasBothPoints) {
@@ -83,23 +102,44 @@ export const createWallStore = () => {
return removedWall;
},
+ peekRemoveWallByPoints: (points) => {
+ const [pointA, pointB] = points;
+
+ const wall = get().walls.find((w) => {
+ const wallPoints = w.points.map((p) => p.pointUuid);
+ return wallPoints.includes(pointA.pointUuid) && wallPoints.includes(pointB.pointUuid);
+ });
+
+ return wall ? JSON.parse(JSON.stringify(wall)) : undefined;
+ },
+
addDecal: (wallUuid, decal) => {
let addedDecal: Decal | undefined;
set((state) => {
- const wallToUpdate = state.walls.find(w => w.wallUuid === wallUuid);
+ const wallToUpdate = state.walls.find((w) => w.wallUuid === wallUuid);
if (wallToUpdate) {
wallToUpdate.decals.push(decal);
addedDecal = JSON.parse(JSON.stringify(decal));
}
- })
+ });
return addedDecal;
},
+ peekAddDecal: (wallUuid, decal) => {
+ const wall = get().walls.find((w) => w.wallUuid === wallUuid);
+ if (!wall) return undefined;
+
+ const clonedWall: Wall = JSON.parse(JSON.stringify(wall));
+ clonedWall.decals.push(JSON.parse(JSON.stringify(decal)));
+
+ return clonedWall;
+ },
+
updateDecal: (decalUuid, decal) => {
let affectedWall: Wall | undefined;
set((state) => {
for (const wall of state.walls) {
- const decalToUpdate = wall.decals.find(d => d.decalUuid === decalUuid);
+ const decalToUpdate = wall.decals.find((d) => d.decalUuid === decalUuid);
if (decalToUpdate) {
Object.assign(decalToUpdate, decal);
affectedWall = JSON.parse(JSON.stringify(wall));
@@ -109,13 +149,27 @@ export const createWallStore = () => {
return affectedWall;
},
+ peekUpdateDecal: (decalUuid, decal) => {
+ const wall = get().walls.find((w) => w.decals.some((d) => d.decalUuid === decalUuid));
+ if (!wall) return undefined;
+
+ const clonedWall: Wall = JSON.parse(JSON.stringify(wall));
+
+ const decalToUpdate = clonedWall.decals.find((d) => d.decalUuid === decalUuid);
+ if (decalToUpdate) {
+ Object.assign(decalToUpdate, decal);
+ }
+
+ return clonedWall;
+ },
+
removeDecal: (decalUuid) => {
let affectedWall: Wall | undefined;
set((state) => {
for (const wall of state.walls) {
- const hasDecal = wall.decals.some(d => d.decalUuid === decalUuid);
+ const hasDecal = wall.decals.some((d) => d.decalUuid === decalUuid);
if (hasDecal) {
- wall.decals = wall.decals.filter(d => d.decalUuid !== decalUuid);
+ wall.decals = wall.decals.filter((d) => d.decalUuid !== decalUuid);
affectedWall = JSON.parse(JSON.stringify(wall));
}
}
@@ -127,42 +181,44 @@ export const createWallStore = () => {
let affectedWall: Wall | undefined;
set((state) => {
for (const wall of state.walls) {
- const decal = wall.decals.find(d => d.decalUuid === decalUuid);
+ const decal = wall.decals.find((d) => d.decalUuid === decalUuid);
if (decal) {
decal.decalPosition = position;
affectedWall = JSON.parse(JSON.stringify(wall));
break;
}
}
- })
+ });
return affectedWall;
},
- updateDecalRotation: (decalUuid, rotation) => set((state) => {
- for (const wall of state.walls) {
- const decal = wall.decals.find(d => d.decalUuid === decalUuid);
- if (decal) {
- decal.decalRotation = rotation;
- break;
+ updateDecalRotation: (decalUuid, rotation) =>
+ set((state) => {
+ for (const wall of state.walls) {
+ const decal = wall.decals.find((d) => d.decalUuid === decalUuid);
+ if (decal) {
+ decal.decalRotation = rotation;
+ break;
+ }
}
- }
- }),
+ }),
- updateDecalScale: (decalUuid, scale) => set((state) => {
- for (const wall of state.walls) {
- const decal = wall.decals.find(d => d.decalUuid === decalUuid);
- if (decal) {
- decal.decalScale = scale;
- break;
+ updateDecalScale: (decalUuid, scale) =>
+ set((state) => {
+ for (const wall of state.walls) {
+ const decal = wall.decals.find((d) => d.decalUuid === decalUuid);
+ if (decal) {
+ decal.decalScale = scale;
+ break;
+ }
}
- }
- }),
+ }),
removePoint: (pointUuid) => {
const removedWalls: Wall[] = [];
set((state) => {
state.walls = state.walls.filter((wall) => {
- const hasPoint = wall.points.some(p => p.pointUuid === pointUuid);
+ const hasPoint = wall.points.some((p) => p.pointUuid === pointUuid);
if (hasPoint) {
removedWalls.push(JSON.parse(JSON.stringify(wall)));
return false;
@@ -173,11 +229,17 @@ export const createWallStore = () => {
return removedWalls;
},
+ peekRemovePoint: (pointUuid) => {
+ const wallsToRemove = get().walls.filter((wall) => wall.points.some((p) => p.pointUuid === pointUuid));
+
+ return wallsToRemove.map((w) => JSON.parse(JSON.stringify(w)));
+ },
+
setPosition: (pointUuid, position) => {
let updatedWalls: Wall[] = [];
set((state) => {
for (const wall of state.walls) {
- const point = wall.points.find(p => p.pointUuid === pointUuid);
+ const point = wall.points.find((p) => p.pointUuid === pointUuid);
if (point) {
point.position = position;
updatedWalls.push(wall);
@@ -187,49 +249,52 @@ export const createWallStore = () => {
return updatedWalls;
},
- setLayer: (pointUuid, layer) => set((state) => {
- for (const wall of state.walls) {
- const point = wall.points.find(p => p.pointUuid === pointUuid);
- if (point) {
- point.layer = layer;
+ setLayer: (pointUuid, layer) =>
+ set((state) => {
+ for (const wall of state.walls) {
+ const point = wall.points.find((p) => p.pointUuid === pointUuid);
+ if (point) {
+ point.layer = layer;
+ }
}
- }
- }),
+ }),
- getWallById: (uuid) => {
- return get().walls.find(w => w.wallUuid === uuid);
+ getWallById: (wallUuid) => {
+ return get().walls.find((w) => w.wallUuid === wallUuid);
},
- getWallsByPointId: (uuid) => {
+ getWallsByPointId: (wallUuid) => {
return get().walls.filter((a) => {
- return JSON.parse(JSON.stringify(a.points.some((p) => p.pointUuid === uuid)));
- })
+ return JSON.parse(JSON.stringify(a.points.some((p) => p.pointUuid === wallUuid)));
+ });
},
getWallByPoints: (point) => {
for (const wall of get().walls) {
- if (((wall.points[0].pointUuid === point[0].pointUuid) || (wall.points[1].pointUuid === point[0].pointUuid)) &&
- ((wall.points[0].pointUuid === point[1].pointUuid) || (wall.points[1].pointUuid === point[1].pointUuid))) {
+ if (
+ (wall.points[0].pointUuid === point[0].pointUuid || wall.points[1].pointUuid === point[0].pointUuid) &&
+ (wall.points[0].pointUuid === point[1].pointUuid || wall.points[1].pointUuid === point[1].pointUuid)
+ ) {
return wall;
}
}
return undefined;
},
- getWallPointById: (uuid) => {
+ getWallPointById: (wallUuid) => {
for (const wall of get().walls) {
- const point = wall.points.find(p => p.pointUuid === uuid);
+ const point = wall.points.find((p) => p.pointUuid === wallUuid);
if (point) return point;
}
return undefined;
},
- getConnectedPoints: (uuid) => {
+ getConnectedPoints: (wallUuid) => {
const connected: Point[] = [];
for (const wall of get().walls) {
for (const point of wall.points) {
- if (point.pointUuid === uuid) {
- connected.push(...wall.points.filter(p => p.pointUuid !== uuid));
+ if (point.pointUuid === wallUuid) {
+ connected.push(...wall.points.filter((p) => p.pointUuid !== wallUuid));
}
}
}
@@ -237,19 +302,18 @@ export const createWallStore = () => {
},
getConnectedWallsByWallId: (wallUuid, skipSelf) => {
- const wall = get().walls.find(w => w.wallUuid === wallUuid);
+ const wall = get().walls.find((w) => w.wallUuid === wallUuid);
if (!wall) return [];
- const pointUuids = wall.points.map(p => p.pointUuid);
+ const pointUuids = wall.points.map((p) => p.pointUuid);
- return get().walls.filter(w => {
+ return get().walls.filter((w) => {
if (skipSelf && w.wallUuid === wallUuid) return false;
- return w.points.some(p => pointUuids.includes(p.pointUuid));
+ return w.points.some((p) => pointUuids.includes(p.pointUuid));
});
},
-
}))
- )
-}
+ );
+};
-export type WallStoreType = ReturnType;
\ No newline at end of file
+export type WallStoreType = ReturnType;