refactor: update aisle retrieval methods for consistency and improve point handling
This commit is contained in:
parent
1a27bb7922
commit
fa5c7eebaa
|
@ -98,7 +98,6 @@ function AisleCreator() {
|
||||||
aisleWidth: aisleWidth
|
aisleWidth: aisleWidth
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log('aisle: ', aisle);
|
|
||||||
addAisle(aisle);
|
addAisle(aisle);
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
createAisleApi(aisle.aisleUuid, aisle.points, aisle.type, projectId)
|
createAisleApi(aisle.aisleUuid, aisle.points, aisle.type, projectId)
|
||||||
|
|
|
@ -19,7 +19,7 @@ function Point({ point }: { readonly point: Point }) {
|
||||||
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
|
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const { toolMode } = useToolMode();
|
const { toolMode } = useToolMode();
|
||||||
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAisleByPointId } = useAisleStore();
|
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = useAisleStore();
|
||||||
const { setPosition: setWallPosition, removePoint: removeWallPoint } = useWallStore();
|
const { setPosition: setWallPosition, removePoint: removeWallPoint } = useWallStore();
|
||||||
const { snapPosition } = useAislePointSnapping(point);
|
const { snapPosition } = useAislePointSnapping(point);
|
||||||
const { checkSnapForAisle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
|
const { checkSnapForAisle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
|
||||||
|
@ -100,7 +100,7 @@ function Point({ point }: { readonly point: Point }) {
|
||||||
const aisleSnappedPosition = snapPosition(newPosition);
|
const aisleSnappedPosition = snapPosition(newPosition);
|
||||||
const finalSnappedPosition = checkSnapForAisle(aisleSnappedPosition.position);
|
const finalSnappedPosition = checkSnapForAisle(aisleSnappedPosition.position);
|
||||||
|
|
||||||
const aislePoints = setAislePosition(point.pointUuid, finalSnappedPosition.position);
|
setAislePosition(point.pointUuid, finalSnappedPosition.position);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (point.pointType === 'Wall') {
|
} else if (point.pointType === 'Wall') {
|
||||||
|
@ -116,11 +116,11 @@ function Point({ point }: { readonly point: Point }) {
|
||||||
const handleDragEnd = (point: Point) => {
|
const handleDragEnd = (point: Point) => {
|
||||||
if (deletePointOrLine) return;
|
if (deletePointOrLine) return;
|
||||||
if (point.pointType === 'Aisle') {
|
if (point.pointType === 'Aisle') {
|
||||||
const aisle = getAisleByPointId(point.pointUuid);
|
const updatedAisles = getAislesByPointId(point.pointUuid);
|
||||||
if (aisle && projectId) {
|
if (updatedAisles.length > 0 && projectId) {
|
||||||
// console.log('Aisle after drag: ', aisle);
|
updatedAisles.forEach((updatedAisle) => {
|
||||||
createAisleApi(aisle.aisleUuid, aisle.points, aisle.type, projectId)
|
createAisleApi(updatedAisle.aisleUuid, updatedAisle.points, updatedAisle.type, projectId)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else if (point.pointType === 'Wall') {
|
} else if (point.pointType === 'Wall') {
|
||||||
// console.log('Wall after drag: ', point);
|
// console.log('Wall after drag: ', point);
|
||||||
|
|
|
@ -41,7 +41,7 @@ interface AisleStore {
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
getAisleById: (uuid: string) => Aisle | undefined;
|
getAisleById: (uuid: string) => Aisle | undefined;
|
||||||
getAisleByPointId: (uuid: string) => Aisle | undefined;
|
getAislesByPointId: (uuid: string) => Aisle[] | [];
|
||||||
getAislePointById: (uuid: string) => Point | undefined;
|
getAislePointById: (uuid: string) => Point | undefined;
|
||||||
getConnectedPoints: (uuid: string) => Point[] | [];
|
getConnectedPoints: (uuid: string) => Point[] | [];
|
||||||
getAisleType: <T extends AisleType>(uuid: string) => T | undefined;
|
getAisleType: <T extends AisleType>(uuid: string) => T | undefined;
|
||||||
|
@ -211,10 +211,10 @@ export const useAisleStore = create<AisleStore>()(
|
||||||
return get().aisles.find((a) => a.aisleUuid === uuid);
|
return get().aisles.find((a) => a.aisleUuid === uuid);
|
||||||
},
|
},
|
||||||
|
|
||||||
getAisleByPointId: (uuid) => {
|
getAislesByPointId: (uuid) => {
|
||||||
return get().aisles.find((a) => {
|
return get().aisles.filter((a) => {
|
||||||
return a.points.some((p) => p.pointUuid === uuid);
|
return a.points.some((p) => p.pointUuid === uuid);
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getAislePointById: (uuid) => {
|
getAislePointById: (uuid) => {
|
||||||
|
|
Loading…
Reference in New Issue