import { Socket } from "socket.io-client"; // import { deleteLineApi } from "../../../../services/factoryBuilder/lines/deleteLineApi"; import * as Types from "../../../../types/world/worldTypes"; import { toast } from "react-toastify"; import { getUserData } from "../../../../functions/getUserData"; function deleteLine( hoveredDeletableLine: Types.RefMesh, onlyFloorlines: Types.RefOnlyFloorLines, lines: Types.RefLines, floorPlanGroupLine: Types.RefGroup, floorPlanGroupPoint: Types.RefGroup, setDeletedLines: any, socket: Socket, projectId?: string, versionId?: string, ): void { const { userId, organization, email } = getUserData(); ////////// Deleting a line and the points if they are not connected to any other line ////////// if (!hoveredDeletableLine.current) { return; } const linePoints = hoveredDeletableLine.current.userData.linePoints; const connectedpoints = [linePoints[0][1], linePoints[1][1]]; //REST // deleteLineApi( // organization, // [ // { "uuid": linePoints[0][1] }, // { "uuid": linePoints[1][1] } // ] // ) //SOCKET const data = { organization, line: [{ uuid: linePoints[0][1] }, { uuid: linePoints[1][1] }], socketId: socket.id, versionId, projectId, userId, }; socket.emit("v1:Line:delete", data); onlyFloorlines.current = onlyFloorlines.current .map((floorline) => floorline.filter( (line) => line[0][1] !== connectedpoints[0] && line[1][1] !== connectedpoints[1] ) ) .filter((floorline) => floorline.length > 0); lines.current = lines.current.filter((item) => item !== linePoints); (hoveredDeletableLine.current.material).dispose(); (hoveredDeletableLine.current.geometry).dispose(); floorPlanGroupLine.current.remove(hoveredDeletableLine.current); setDeletedLines([linePoints]); connectedpoints.forEach((pointUUID) => { let isConnected = false; floorPlanGroupLine.current.children.forEach((line) => { const linePoints = line.userData.linePoints; const uuid1 = linePoints[0][1]; const uuid2 = linePoints[1][1]; if (uuid1 === pointUUID || uuid2 === pointUUID) { isConnected = true; } }); if (!isConnected) { floorPlanGroupPoint.current.children.forEach((point: any) => { if (point.uuid === pointUUID) { (point.material).dispose(); (point.geometry).dispose(); floorPlanGroupPoint.current.remove(point); } }); } }); echo.success("Line Removed!"); } export default deleteLine;