From 8dc6b3949fbad8e96d0782e54ca6d3cda0acfbed Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Fri, 4 Apr 2025 17:46:19 +0530 Subject: [PATCH] refactor: update event handling in mechanics components to use socket communication --- .../mechanics/ConveyorMechanics.tsx | 22 +++++++++++++---- .../mechanics/VehicleMechanics.tsx | 23 +++++++++++++----- .../modules/builder/agv/navMeshDetails.tsx | 2 +- .../builder/groups/floorItemsGroup.tsx | 1 - .../selection/duplicationControls.tsx | 24 +++++++++---------- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx b/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx index 0a20f4b..8ad0886 100644 --- a/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx +++ b/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx @@ -14,6 +14,7 @@ import { useSelectedActionSphere, useSelectedPath, useSimulationPaths, + useSocketStore, } from "../../../../store/store"; import * as THREE from "three"; import * as Types from "../../../../types/world/worldTypes"; @@ -26,6 +27,7 @@ const ConveyorMechanics: React.FC = () => { const { selectedPath, setSelectedPath } = useSelectedPath(); const { simulationPaths, setSimulationPaths } = useSimulationPaths(); const { floorItems, setFloorItems } = useFloorItems(); + const { socket } = useSocketStore(); const actionsContainerRef = useRef(null); const triggersContainerRef = useRef(null); @@ -44,11 +46,21 @@ const ConveyorMechanics: React.FC = () => { if (!updatedPath) return; const email = localStorage.getItem("email"); const organization = email ? email.split("@")[1].split(".")[0] : ""; - await setEventApi( - organization, - updatedPath.modeluuid, - { type: "Conveyor", points: updatedPath.points, speed: updatedPath.speed } - ); + + // await setEventApi( + // organization, + // updatedPath.modeluuid, + // { type: "Conveyor", points: updatedPath.points, speed: updatedPath.speed } + // ); + + const data = { + organization: organization, + modeluuid: updatedPath.modeluuid, + eventData: { type: "Conveyor", points: updatedPath.points, speed: updatedPath.speed } + } + + socket.emit('v2:model-asset:updateEventData', data); + } const handleAddAction = () => { diff --git a/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx b/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx index f1929ad..e9bd6a2 100644 --- a/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx +++ b/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx @@ -1,7 +1,7 @@ import React, { useRef, useMemo } from "react"; import { InfoIcon } from "../../../icons/ExportCommonIcons"; import InputWithDropDown from "../../../ui/inputs/InputWithDropDown"; -import { useEditingPoint, useEyeDropMode, usePreviewPosition, useSelectedActionSphere, useSimulationPaths } from "../../../../store/store"; +import { useEditingPoint, useEyeDropMode, usePreviewPosition, useSelectedActionSphere, useSimulationPaths, useSocketStore } from "../../../../store/store"; import * as Types from '../../../../types/world/worldTypes'; import PositionInput from "../customInput/PositionInputs"; import { setEventApi } from "../../../../services/factoryBuilder/assest/floorAsset/setEventsApt"; @@ -12,6 +12,7 @@ const VehicleMechanics: React.FC = () => { const { eyeDropMode, setEyeDropMode } = useEyeDropMode(); const { editingPoint, setEditingPoint } = useEditingPoint(); const { previewPosition, setPreviewPosition } = usePreviewPosition(); + const { socket } = useSocketStore(); const propertiesContainerRef = useRef(null); @@ -45,11 +46,21 @@ const VehicleMechanics: React.FC = () => { if (!updatedPath) return; const email = localStorage.getItem("email"); const organization = email ? email.split("@")[1].split(".")[0] : ""; - await setEventApi( - organization, - updatedPath.modeluuid, - { type: "Vehicle", points: updatedPath.points } - ); + + // await setEventApi( + // organization, + // updatedPath.modeluuid, + // { type: "Vehicle", points: updatedPath.points } + // ); + + const data = { + organization: organization, + modeluuid: updatedPath.modeluuid, + eventData: { type: "Vehicle", points: updatedPath.points } + } + + socket.emit('v2:model-asset:updateEventData', data); + } const handleActionUpdate = React.useCallback((updatedAction: Partial) => { diff --git a/app/src/modules/builder/agv/navMeshDetails.tsx b/app/src/modules/builder/agv/navMeshDetails.tsx index 54b3c7c..626b673 100644 --- a/app/src/modules/builder/agv/navMeshDetails.tsx +++ b/app/src/modules/builder/agv/navMeshDetails.tsx @@ -54,7 +54,7 @@ export default function NavMeshDetails({ const debugDrawer = new DebugDrawer(); debugDrawer.drawNavMesh(navMesh); - scene.add(debugDrawer); + // scene.add(debugDrawer); } catch (error) { } }; diff --git a/app/src/modules/builder/groups/floorItemsGroup.tsx b/app/src/modules/builder/groups/floorItemsGroup.tsx index 2b77fb2..cef7d74 100644 --- a/app/src/modules/builder/groups/floorItemsGroup.tsx +++ b/app/src/modules/builder/groups/floorItemsGroup.tsx @@ -110,7 +110,6 @@ const FloorItemsGroup = ({ } gltfLoaderWorker.postMessage({ floorItems: data }); } else { - console.log('data: ', data); gltfLoaderWorker.postMessage({ floorItems: [] }); loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationPaths); updateLoadingProgress(100); diff --git a/app/src/modules/scene/controls/selection/duplicationControls.tsx b/app/src/modules/scene/controls/selection/duplicationControls.tsx index 8f3b514..c28c401 100644 --- a/app/src/modules/scene/controls/selection/duplicationControls.tsx +++ b/app/src/modules/scene/controls/selection/duplicationControls.tsx @@ -263,17 +263,17 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb // API - setFloorItemApi( - organization, - obj.uuid, - obj.userData.name, - obj.userData.modelId, - [worldPosition.x, worldPosition.y, worldPosition.z], - { "x": obj.rotation.x, "y": obj.rotation.y, "z": obj.rotation.z }, - false, - true, - { type: backendEventData.type, points: backendEventData.points } - ); + // setFloorItemApi( + // organization, + // obj.uuid, + // obj.userData.name, + // obj.userData.modelId, + // [worldPosition.x, worldPosition.y, worldPosition.z], + // { "x": obj.rotation.x, "y": obj.rotation.y, "z": obj.rotation.z }, + // false, + // true, + // { type: backendEventData.type, points: backendEventData.points } + // ); // SOCKET @@ -300,7 +300,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb newEventData as Types.VehicleEventsSchema ]); - // socket.emit("v2:model-asset:add", data); + socket.emit("v2:model-asset:add", data); } } else {