updated
This commit is contained in:
@@ -18,6 +18,8 @@ import * as turf from "@turf/turf";
|
||||
import { computeArea } from "../functions/computeArea";
|
||||
import { useSelectedZoneStore } from "../../../store/visualization/useZoneStore";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { getUserData } from "../../../functions/getUserData";
|
||||
import { useVersionContext } from "../version/versionContext";
|
||||
|
||||
const ZoneGroup: React.FC = () => {
|
||||
const { camera, pointer, gl, raycaster, scene, controls } = useThree();
|
||||
@@ -27,19 +29,17 @@ const ZoneGroup: React.FC = () => {
|
||||
const { zonePoints, setZonePoints } = useZonePoints();
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const { selectedZone } = useSelectedZoneStore();
|
||||
const [draggedSphere, setDraggedSphere] = useState<THREE.Vector3 | null>(
|
||||
null
|
||||
);
|
||||
const plane = useMemo(
|
||||
() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0),
|
||||
[]
|
||||
);
|
||||
const [draggedSphere, setDraggedSphere] = useState<THREE.Vector3 | null>(null);
|
||||
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
|
||||
const { toggleView } = useToggleView();
|
||||
const { removedLayer, setRemovedLayer } = useRemovedLayer();
|
||||
const { toolMode } = useToolMode();
|
||||
const { activeLayer } = useActiveLayer();
|
||||
const { socket } = useSocketStore();
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
const { projectId } = useParams();
|
||||
const { userId, organization, email } = getUserData();
|
||||
|
||||
const groupsRef = useRef<any>();
|
||||
|
||||
@@ -72,15 +72,8 @@ const ZoneGroup: React.FC = () => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchZones = async () => {
|
||||
const email = localStorage.getItem("email");
|
||||
if (!email) return;
|
||||
|
||||
const organization = email.split("@")[1].split(".")[0];
|
||||
const data = await getZonesApi(organization, projectId);
|
||||
// console.log('data: ', data);
|
||||
|
||||
if (data.length > 0) {
|
||||
getZonesApi(organization, projectId, selectedVersion?.versionId || '').then((data) => {
|
||||
if (data && data.length > 0) {
|
||||
const fetchedZones = data.map((zone: any) => ({
|
||||
zoneUuid: zone.zoneUuid,
|
||||
zoneName: zone.zoneName,
|
||||
@@ -97,11 +90,13 @@ const ZoneGroup: React.FC = () => {
|
||||
);
|
||||
|
||||
setZonePoints(fetchedPoints);
|
||||
}else{
|
||||
setZones([]);
|
||||
}
|
||||
};
|
||||
|
||||
fetchZones();
|
||||
}, []);
|
||||
}).catch((err)=>{
|
||||
console.error(err);
|
||||
})
|
||||
}, [selectedVersion?.versionId]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem("zones", JSON.stringify(zones));
|
||||
@@ -142,9 +137,6 @@ const ZoneGroup: React.FC = () => {
|
||||
points: [number, number, number][];
|
||||
layer: string;
|
||||
}) => {
|
||||
const email = localStorage.getItem("email");
|
||||
const userId = localStorage.getItem("userId");
|
||||
const organization = email!.split("@")[1].split(".")[0];
|
||||
|
||||
const calculateCenter = (points: number[][]) => {
|
||||
if (!points || points.length === 0) return null;
|
||||
@@ -171,8 +163,9 @@ const ZoneGroup: React.FC = () => {
|
||||
|
||||
const input = {
|
||||
userId: userId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
projectId,
|
||||
organization: organization,
|
||||
organization,
|
||||
zoneData: {
|
||||
zoneName: zone.zoneName,
|
||||
zoneUuid: zone.zoneUuid,
|
||||
@@ -193,9 +186,6 @@ const ZoneGroup: React.FC = () => {
|
||||
points: [number, number, number][];
|
||||
layer: string;
|
||||
}) => {
|
||||
const email = localStorage.getItem("email");
|
||||
const userId = localStorage.getItem("userId");
|
||||
const organization = email!.split("@")[1].split(".")[0];
|
||||
|
||||
const calculateCenter = (points: number[][]) => {
|
||||
if (!points || points.length === 0) return null;
|
||||
@@ -222,8 +212,9 @@ const ZoneGroup: React.FC = () => {
|
||||
|
||||
const input = {
|
||||
userId: userId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
projectId,
|
||||
organization: organization,
|
||||
organization,
|
||||
zoneData: {
|
||||
zoneName: zone.zoneName,
|
||||
zoneUuid: zone.zoneUuid,
|
||||
@@ -238,14 +229,12 @@ const ZoneGroup: React.FC = () => {
|
||||
};
|
||||
|
||||
const deleteZoneFromBackend = async (zoneUuid: string) => {
|
||||
const email = localStorage.getItem("email");
|
||||
const userId = localStorage.getItem("userId");
|
||||
const organization = email!.split("@")[1].split(".")[0];
|
||||
|
||||
const input = {
|
||||
userId: userId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
projectId,
|
||||
organization: organization,
|
||||
organization,
|
||||
zoneUuid: zoneUuid,
|
||||
};
|
||||
|
||||
@@ -447,7 +436,7 @@ const ZoneGroup: React.FC = () => {
|
||||
canvasElement.removeEventListener("mousemove", onMouseMove);
|
||||
canvasElement.removeEventListener("contextmenu", onContext);
|
||||
};
|
||||
}, [gl, camera, startPoint, toggleView, scene, toolMode, zones, isDragging, zonePoints, draggedSphere, activeLayer, raycaster, pointer, controls, plane, setZones, setZonePoints, addZoneToBackend, handleDeleteZone, updateZoneToBackend,]);
|
||||
}, [gl, camera, startPoint, toggleView, scene, toolMode, zones, isDragging, zonePoints, draggedSphere, activeLayer, raycaster, pointer, controls, plane, setZones, setZonePoints, addZoneToBackend, handleDeleteZone, updateZoneToBackend, selectedVersion?.versionId]);
|
||||
|
||||
useFrame(() => {
|
||||
if (!startPoint) return;
|
||||
|
||||
Reference in New Issue
Block a user