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
|
||||
}
|
||||
};
|
||||
console.log('aisle: ', aisle);
|
||||
addAisle(aisle);
|
||||
if (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 [isHovered, setIsHovered] = useState(false);
|
||||
const { toolMode } = useToolMode();
|
||||
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAisleByPointId } = useAisleStore();
|
||||
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = useAisleStore();
|
||||
const { setPosition: setWallPosition, removePoint: removeWallPoint } = useWallStore();
|
||||
const { snapPosition } = useAislePointSnapping(point);
|
||||
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 finalSnappedPosition = checkSnapForAisle(aisleSnappedPosition.position);
|
||||
|
||||
const aislePoints = setAislePosition(point.pointUuid, finalSnappedPosition.position);
|
||||
setAislePosition(point.pointUuid, finalSnappedPosition.position);
|
||||
|
||||
}
|
||||
} else if (point.pointType === 'Wall') {
|
||||
|
@ -116,11 +116,11 @@ function Point({ point }: { readonly point: Point }) {
|
|||
const handleDragEnd = (point: Point) => {
|
||||
if (deletePointOrLine) return;
|
||||
if (point.pointType === 'Aisle') {
|
||||
const aisle = getAisleByPointId(point.pointUuid);
|
||||
if (aisle && projectId) {
|
||||
// console.log('Aisle after drag: ', aisle);
|
||||
createAisleApi(aisle.aisleUuid, aisle.points, aisle.type, projectId)
|
||||
|
||||
const updatedAisles = getAislesByPointId(point.pointUuid);
|
||||
if (updatedAisles.length > 0 && projectId) {
|
||||
updatedAisles.forEach((updatedAisle) => {
|
||||
createAisleApi(updatedAisle.aisleUuid, updatedAisle.points, updatedAisle.type, projectId)
|
||||
})
|
||||
}
|
||||
} else if (point.pointType === 'Wall') {
|
||||
// console.log('Wall after drag: ', point);
|
||||
|
|
|
@ -41,7 +41,7 @@ interface AisleStore {
|
|||
) => void;
|
||||
|
||||
getAisleById: (uuid: string) => Aisle | undefined;
|
||||
getAisleByPointId: (uuid: string) => Aisle | undefined;
|
||||
getAislesByPointId: (uuid: string) => Aisle[] | [];
|
||||
getAislePointById: (uuid: string) => Point | undefined;
|
||||
getConnectedPoints: (uuid: string) => Point[] | [];
|
||||
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);
|
||||
},
|
||||
|
||||
getAisleByPointId: (uuid) => {
|
||||
return get().aisles.find((a) => {
|
||||
getAislesByPointId: (uuid) => {
|
||||
return get().aisles.filter((a) => {
|
||||
return a.points.some((p) => p.pointUuid === uuid);
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
getAislePointById: (uuid) => {
|
||||
|
|
Loading…
Reference in New Issue