import { Button } from "../ui/button"; import { Polygon } from "@/types/canvas"; type PolygonCanvasProps = { camera: string; width: number; height: number; polygons: Polygon[]; setPolygons: React.Dispatch>; activePolygonIndex: number | null; setActivePolygonIndex: React.Dispatch>; }; export function PolygonControls({ polygons, setPolygons, activePolygonIndex, setActivePolygonIndex, }: PolygonCanvasProps) { const undo = () => { if (activePolygonIndex !== null && polygons) { const updatedPolygons = [...polygons]; const activePolygon = updatedPolygons[activePolygonIndex]; if (activePolygon.points.length > 0) { updatedPolygons[activePolygonIndex] = { ...activePolygon, points: activePolygon.points.slice(0, -1), isFinished: false, }; setPolygons(updatedPolygons); } } }; const reset = () => { if (activePolygonIndex !== null) { const updatedPolygons = [...polygons]; updatedPolygons[activePolygonIndex] = { points: [], isFinished: false, name: "new", }; setPolygons(updatedPolygons); } }; const handleNewPolygon = () => { setPolygons([ ...(polygons || []), { points: [], isFinished: false, name: "new", }, ]); console.log(polygons.length); console.log(polygons); console.log("active index", polygons.length); setActivePolygonIndex(polygons.length); }; return (
); } export default PolygonControls;