frigate/web/src/components/settings/PolygonEditControls.tsx

76 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-04-14 07:23:54 +03:00
import { Polygon } from "@/types/canvas";
2024-04-15 02:36:39 +03:00
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
import { MdOutlineRestartAlt, MdUndo } from "react-icons/md";
2024-04-14 07:23:54 +03:00
import { Button } from "../ui/button";
type PolygonEditControlsProps = {
polygons: Polygon[];
setPolygons: React.Dispatch<React.SetStateAction<Polygon[]>>;
2024-04-15 02:36:39 +03:00
activePolygonIndex: number | undefined;
2024-04-14 07:23:54 +03:00
};
export default function PolygonEditControls({
polygons,
setPolygons,
activePolygonIndex,
}: PolygonEditControlsProps) {
const undo = () => {
2024-04-15 02:36:39 +03:00
if (activePolygonIndex === undefined || !polygons) {
return;
2024-04-14 07:23:54 +03:00
}
2024-04-15 02:36:39 +03:00
const updatedPolygons = [...polygons];
const activePolygon = updatedPolygons[activePolygonIndex];
updatedPolygons[activePolygonIndex] = {
...activePolygon,
points: [...activePolygon.points.slice(0, -1)],
isFinished: false,
};
setPolygons(updatedPolygons);
2024-04-14 07:23:54 +03:00
};
const reset = () => {
2024-04-15 02:36:39 +03:00
if (activePolygonIndex === undefined || !polygons) {
return;
2024-04-14 07:23:54 +03:00
}
2024-04-15 02:36:39 +03:00
const updatedPolygons = [...polygons];
const activePolygon = updatedPolygons[activePolygonIndex];
updatedPolygons[activePolygonIndex] = {
...activePolygon,
points: [],
isFinished: false,
};
setPolygons(updatedPolygons);
2024-04-14 07:23:54 +03:00
};
return (
2024-04-15 02:36:39 +03:00
<div className="flex flex-row justify-center gap-2">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="secondary"
className="size-6 p-1 rounded-md text-background bg-secondary-foreground"
onClick={undo}
>
<MdUndo />
</Button>
</TooltipTrigger>
<TooltipContent>Undo</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="secondary"
className="size-6 p-1 rounded-md text-background bg-secondary-foreground"
onClick={reset}
>
<MdOutlineRestartAlt />
</Button>
</TooltipTrigger>
<TooltipContent>Reset</TooltipContent>
</Tooltip>
2024-04-14 07:23:54 +03:00
</div>
);
}