Refactor floor management components and APIs: enhance FloorInstance for shape creation, update FloorInstances to handle floor rendering and UUID tracking, and improve FloorCreator with project and version context. Modify floor store methods for better floor management and integrate API calls for floor upsert and deletion. Adjust wall and point components to support new floor functionalities.
This commit is contained in:
@@ -6,12 +6,15 @@ import { useSocketStore, useToolMode } from '../../../store/builder/store';
|
||||
import { useBuilderStore } from '../../../store/builder/useBuilderStore';
|
||||
import { useSceneContext } from '../../scene/sceneContext';
|
||||
import * as Constants from '../../../types/world/worldConstants';
|
||||
import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
||||
import { useVersionContext } from '../version/versionContext';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
||||
import { getUserData } from '../../../functions/getUserData';
|
||||
|
||||
// import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
||||
// import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
||||
import { upsertFloorApi } from '../../../services/factoryBuilder/floor/upsertFloorApi';
|
||||
import { deleteFloorApi } from '../../../services/factoryBuilder/floor/deleteFloorApi';
|
||||
|
||||
interface LineProps {
|
||||
points: [Point, Point];
|
||||
}
|
||||
@@ -25,7 +28,7 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
const { toolMode } = useToolMode();
|
||||
const { wallStore, floorStore } = useSceneContext();
|
||||
const { removeWallByPoints, setPosition: setWallPosition, getWallsByPointId } = wallStore();
|
||||
const { removeFloorByPoints, setPosition: setFloorPosition } = floorStore();
|
||||
const { removeFloorByPoints, setPosition: setFloorPosition, getFloorsByPointId } = floorStore();
|
||||
const { userId, organization } = getUserData();
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
@@ -112,7 +115,52 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
setHoveredLine(null);
|
||||
}
|
||||
if (points[0].pointType === 'Floor' && points[1].pointType === 'Floor') {
|
||||
removeFloorByPoints(points);
|
||||
const { removedFloors, updatedFloors } = removeFloorByPoints(points);
|
||||
if (removedFloors.length > 0) {
|
||||
removedFloors.forEach(floor => {
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
|
||||
// deleteFloorApi(projectId, selectedVersion?.versionId || '', floor.floorUuid);
|
||||
|
||||
// SOCKET
|
||||
|
||||
const data = {
|
||||
floorUuid: floor.floorUuid,
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
userId: userId,
|
||||
organization: organization
|
||||
}
|
||||
|
||||
socket.emit('v1:model-Floor:delete', data);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (updatedFloors.length > 0) {
|
||||
updatedFloors.forEach(floor => {
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
|
||||
// upsertFloorApi(projectId, selectedVersion?.versionId || '', floor);
|
||||
|
||||
// SOCKET
|
||||
|
||||
const data = {
|
||||
floorData: floor,
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
userId: userId,
|
||||
organization: organization
|
||||
}
|
||||
|
||||
socket.emit('v1:model-Floor:add', data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setHoveredLine(null);
|
||||
}
|
||||
gl.domElement.style.cursor = 'default';
|
||||
@@ -197,7 +245,32 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
})
|
||||
}
|
||||
} else if (points[0].pointType === 'Floor' && points[1].pointType === 'Floor') {
|
||||
// Handle floor update logic here if needed
|
||||
const updatedFloors1 = getFloorsByPointId(points[0].pointUuid);
|
||||
const updatedFloors2 = getFloorsByPointId(points[1].pointUuid);
|
||||
const updatedFloors = [...updatedFloors1, ...updatedFloors2].filter((floor, index, self) => index === self.findIndex((f) => f.floorUuid === floor.floorUuid));
|
||||
|
||||
if (updatedFloors.length > 0 && projectId) {
|
||||
updatedFloors.forEach(updatedFloor => {
|
||||
|
||||
// API
|
||||
|
||||
// upsertFloorApi(projectId, selectedVersion?.versionId || '', updatedFloor).catch((error) => {
|
||||
// console.error('Error updating floor:', error);
|
||||
// });
|
||||
|
||||
// SOCKET
|
||||
|
||||
const data = {
|
||||
floorData: updatedFloor,
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
userId: userId,
|
||||
organization: organization
|
||||
}
|
||||
|
||||
socket.emit('v1:model-Floor:add', data);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user