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:
@@ -7,8 +7,8 @@ interface FloorStore {
|
||||
addFloor: (floor: Floor) => void;
|
||||
updateFloor: (uuid: string, updated: Partial<Floor>) => void;
|
||||
removeFloor: (uuid: string) => void;
|
||||
removePoint: (pointUuid: string) => Floor[];
|
||||
removeFloorByPoints: (Points: [Point, Point]) => Floor[];
|
||||
removePoint: (pointUuid: string) => { removedFloors: Floor[], updatedFloors: Floor[] };
|
||||
removeFloorByPoints: (Points: [Point, Point]) => { removedFloors: Floor[], updatedFloors: Floor[] };
|
||||
clearFloors: () => void;
|
||||
setPosition: (
|
||||
pointUuid: string,
|
||||
@@ -26,7 +26,7 @@ interface FloorStore {
|
||||
updateDecalScale: (decalUuid: string, scale: number) => void;
|
||||
|
||||
getFloorById: (uuid: string) => Floor | undefined;
|
||||
getFloorsByPointId: (uuid: string) => Floor | undefined;
|
||||
getFloorsByPointId: (uuid: string) => Floor[] | [];
|
||||
getFloorByPoints: (points: Point[]) => Floor | undefined;
|
||||
getFloorPointById: (uuid: string) => Point | undefined;
|
||||
getConnectedPoints: (uuid: string) => Point[];
|
||||
@@ -58,47 +58,46 @@ export const createFloorStore = () => {
|
||||
|
||||
removePoint: (pointUuid) => {
|
||||
const removedFloors: Floor[] = [];
|
||||
const updatedFloors: Floor[] = [];
|
||||
|
||||
set(state => {
|
||||
const updatedFloors: Floor[] = [];
|
||||
|
||||
for (const floor of state.floors) {
|
||||
const hasPoint = floor.points.some(p => p.pointUuid === pointUuid);
|
||||
if (!hasPoint) {
|
||||
updatedFloors.push(floor);
|
||||
const pointIndex = floor.points.findIndex(p => p.pointUuid === pointUuid);
|
||||
if (pointIndex === -1) {
|
||||
updatedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
continue;
|
||||
}
|
||||
|
||||
const remainingPoints = floor.points.filter(p => p.pointUuid !== pointUuid);
|
||||
if (remainingPoints.length > 2) {
|
||||
floor.points = remainingPoints;
|
||||
updatedFloors.push(floor);
|
||||
} else {
|
||||
removedFloors.push(floor);
|
||||
|
||||
if (remainingPoints.length <= 2) {
|
||||
removedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
continue;
|
||||
}
|
||||
floor.points = remainingPoints;
|
||||
updatedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
}
|
||||
|
||||
state.floors = updatedFloors;
|
||||
});
|
||||
|
||||
return removedFloors;
|
||||
return { removedFloors, updatedFloors };
|
||||
},
|
||||
|
||||
removeFloorByPoints: ([pointA, pointB]) => {
|
||||
const removedFloors: Floor[] = [];
|
||||
const updatedFloors: Floor[] = [];
|
||||
|
||||
set(state => {
|
||||
const updatedFloors: Floor[] = [];
|
||||
|
||||
for (const floor of state.floors) {
|
||||
const indices = floor.points
|
||||
.map((p, i) => ({ uuid: p.pointUuid, index: i }));
|
||||
const indices = floor.points.map((p, i) => ({ uuid: p.pointUuid, index: i }));
|
||||
|
||||
const idxA = indices.find(i => i.uuid === pointA.pointUuid)?.index ?? -1;
|
||||
const idxB = indices.find(i => i.uuid === pointB.pointUuid)?.index ?? -1;
|
||||
|
||||
if (idxA === -1 || idxB === -1) {
|
||||
updatedFloors.push(floor);
|
||||
updatedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -108,7 +107,7 @@ export const createFloorStore = () => {
|
||||
(idxB === 0 && idxA === floor.points.length - 1);
|
||||
|
||||
if (!areAdjacent) {
|
||||
updatedFloors.push(floor);
|
||||
updatedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -118,16 +117,16 @@ export const createFloorStore = () => {
|
||||
|
||||
if (remainingPoints.length > 2) {
|
||||
floor.points = remainingPoints;
|
||||
updatedFloors.push(floor);
|
||||
updatedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
} else {
|
||||
removedFloors.push(floor);
|
||||
removedFloors.push(JSON.parse(JSON.stringify(floor)));
|
||||
}
|
||||
}
|
||||
|
||||
state.floors = updatedFloors;
|
||||
});
|
||||
|
||||
return removedFloors;
|
||||
return { removedFloors, updatedFloors };
|
||||
},
|
||||
|
||||
clearFloors: () => set(state => {
|
||||
@@ -236,9 +235,9 @@ export const createFloorStore = () => {
|
||||
},
|
||||
|
||||
getFloorsByPointId: (pointUuid) => {
|
||||
return get().floors.find(floor =>
|
||||
floor.points.some(p => p.pointUuid === pointUuid)
|
||||
);
|
||||
return get().floors.filter(floor => {
|
||||
return floor.points.some(p => p.pointUuid === pointUuid);
|
||||
});
|
||||
},
|
||||
|
||||
getFloorByPoints: (points) => {
|
||||
|
||||
Reference in New Issue
Block a user