refactor: update event handling in mechanics components to use socket communication

This commit is contained in:
Jerald-Golden-B 2025-04-04 17:46:19 +05:30
parent cf6946750b
commit 8dc6b3949f
5 changed files with 47 additions and 25 deletions

View File

@ -14,6 +14,7 @@ import {
useSelectedActionSphere, useSelectedActionSphere,
useSelectedPath, useSelectedPath,
useSimulationPaths, useSimulationPaths,
useSocketStore,
} from "../../../../store/store"; } from "../../../../store/store";
import * as THREE from "three"; import * as THREE from "three";
import * as Types from "../../../../types/world/worldTypes"; import * as Types from "../../../../types/world/worldTypes";
@ -26,6 +27,7 @@ const ConveyorMechanics: React.FC = () => {
const { selectedPath, setSelectedPath } = useSelectedPath(); const { selectedPath, setSelectedPath } = useSelectedPath();
const { simulationPaths, setSimulationPaths } = useSimulationPaths(); const { simulationPaths, setSimulationPaths } = useSimulationPaths();
const { floorItems, setFloorItems } = useFloorItems(); const { floorItems, setFloorItems } = useFloorItems();
const { socket } = useSocketStore();
const actionsContainerRef = useRef<HTMLDivElement>(null); const actionsContainerRef = useRef<HTMLDivElement>(null);
const triggersContainerRef = useRef<HTMLDivElement>(null); const triggersContainerRef = useRef<HTMLDivElement>(null);
@ -44,11 +46,21 @@ const ConveyorMechanics: React.FC = () => {
if (!updatedPath) return; if (!updatedPath) return;
const email = localStorage.getItem("email"); const email = localStorage.getItem("email");
const organization = email ? email.split("@")[1].split(".")[0] : ""; const organization = email ? email.split("@")[1].split(".")[0] : "";
await setEventApi(
organization, // await setEventApi(
updatedPath.modeluuid, // organization,
{ type: "Conveyor", points: updatedPath.points, speed: updatedPath.speed } // 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 = () => { const handleAddAction = () => {

View File

@ -1,7 +1,7 @@
import React, { useRef, useMemo } from "react"; import React, { useRef, useMemo } from "react";
import { InfoIcon } from "../../../icons/ExportCommonIcons"; import { InfoIcon } from "../../../icons/ExportCommonIcons";
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown"; 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 * as Types from '../../../../types/world/worldTypes';
import PositionInput from "../customInput/PositionInputs"; import PositionInput from "../customInput/PositionInputs";
import { setEventApi } from "../../../../services/factoryBuilder/assest/floorAsset/setEventsApt"; import { setEventApi } from "../../../../services/factoryBuilder/assest/floorAsset/setEventsApt";
@ -12,6 +12,7 @@ const VehicleMechanics: React.FC = () => {
const { eyeDropMode, setEyeDropMode } = useEyeDropMode(); const { eyeDropMode, setEyeDropMode } = useEyeDropMode();
const { editingPoint, setEditingPoint } = useEditingPoint(); const { editingPoint, setEditingPoint } = useEditingPoint();
const { previewPosition, setPreviewPosition } = usePreviewPosition(); const { previewPosition, setPreviewPosition } = usePreviewPosition();
const { socket } = useSocketStore();
const propertiesContainerRef = useRef<HTMLDivElement>(null); const propertiesContainerRef = useRef<HTMLDivElement>(null);
@ -45,11 +46,21 @@ const VehicleMechanics: React.FC = () => {
if (!updatedPath) return; if (!updatedPath) return;
const email = localStorage.getItem("email"); const email = localStorage.getItem("email");
const organization = email ? email.split("@")[1].split(".")[0] : ""; const organization = email ? email.split("@")[1].split(".")[0] : "";
await setEventApi(
organization, // await setEventApi(
updatedPath.modeluuid, // organization,
{ type: "Vehicle", points: updatedPath.points } // 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<Types.VehicleEventsSchema['points']['actions']>) => { const handleActionUpdate = React.useCallback((updatedAction: Partial<Types.VehicleEventsSchema['points']['actions']>) => {

View File

@ -54,7 +54,7 @@ export default function NavMeshDetails({
const debugDrawer = new DebugDrawer(); const debugDrawer = new DebugDrawer();
debugDrawer.drawNavMesh(navMesh); debugDrawer.drawNavMesh(navMesh);
scene.add(debugDrawer); // scene.add(debugDrawer);
} catch (error) { } } catch (error) { }
}; };

View File

@ -110,7 +110,6 @@ const FloorItemsGroup = ({
} }
gltfLoaderWorker.postMessage({ floorItems: data }); gltfLoaderWorker.postMessage({ floorItems: data });
} else { } else {
console.log('data: ', data);
gltfLoaderWorker.postMessage({ floorItems: [] }); gltfLoaderWorker.postMessage({ floorItems: [] });
loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationPaths); loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationPaths);
updateLoadingProgress(100); updateLoadingProgress(100);

View File

@ -263,17 +263,17 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb
// API // API
setFloorItemApi( // setFloorItemApi(
organization, // organization,
obj.uuid, // obj.uuid,
obj.userData.name, // obj.userData.name,
obj.userData.modelId, // obj.userData.modelId,
[worldPosition.x, worldPosition.y, worldPosition.z], // [worldPosition.x, worldPosition.y, worldPosition.z],
{ "x": obj.rotation.x, "y": obj.rotation.y, "z": obj.rotation.z }, // { "x": obj.rotation.x, "y": obj.rotation.y, "z": obj.rotation.z },
false, // false,
true, // true,
{ type: backendEventData.type, points: backendEventData.points } // { type: backendEventData.type, points: backendEventData.points }
); // );
// SOCKET // SOCKET
@ -300,7 +300,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb
newEventData as Types.VehicleEventsSchema newEventData as Types.VehicleEventsSchema
]); ]);
// socket.emit("v2:model-asset:add", data); socket.emit("v2:model-asset:add", data);
} }
} else { } else {