refactor: update aisle retrieval methods for consistency and improve point handling

This commit is contained in:
Jerald-Golden-B 2025-06-05 16:30:16 +05:30
parent 1a27bb7922
commit fa5c7eebaa
3 changed files with 11 additions and 12 deletions

View File

@ -98,7 +98,6 @@ function AisleCreator() {
aisleWidth: aisleWidth
}
};
console.log('aisle: ', aisle);
addAisle(aisle);
if (projectId) {
createAisleApi(aisle.aisleUuid, aisle.points, aisle.type, projectId)

View File

@ -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);

View File

@ -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) => {