2025-08-13 14:23:48 +01:00
|
|
|
import { useGetOverviewSnapshot } from "../../hooks/useGetOverviewSnapshot";
|
2025-08-15 09:32:33 +01:00
|
|
|
import NavigationArrow from "../UI/NavigationArrow";
|
2025-11-04 16:09:24 +00:00
|
|
|
|
2025-10-06 14:21:56 +01:00
|
|
|
import Loading from "../UI/Loading";
|
|
|
|
|
import ErrorState from "../UI/ErrorState";
|
2025-08-13 14:23:48 +01:00
|
|
|
type SnapshotContainerProps = {
|
|
|
|
|
side: string;
|
2025-08-18 12:53:30 +01:00
|
|
|
settingsPage?: boolean;
|
2025-10-02 16:07:05 +01:00
|
|
|
zoomLevel?: number;
|
|
|
|
|
onZoomLevelChange?: (level: number) => void;
|
2025-08-13 14:23:48 +01:00
|
|
|
};
|
|
|
|
|
|
2025-11-04 13:38:06 +00:00
|
|
|
export const SnapshotContainer = ({ side, settingsPage, zoomLevel, onZoomLevelChange }: SnapshotContainerProps) => {
|
2025-09-30 11:11:46 +01:00
|
|
|
const { canvasRef, isError, isPending } = useGetOverviewSnapshot(side);
|
2025-08-13 14:23:48 +01:00
|
|
|
|
2025-10-02 16:07:05 +01:00
|
|
|
const handleZoomClick = () => {
|
|
|
|
|
const baseLevel = zoomLevel ?? 1;
|
2025-11-04 13:38:06 +00:00
|
|
|
const newLevel = baseLevel >= 4 ? 1 : baseLevel * 2;
|
2025-09-29 15:21:22 +01:00
|
|
|
|
2025-10-02 16:07:05 +01:00
|
|
|
if (onZoomLevelChange) onZoomLevelChange(newLevel);
|
2025-10-01 11:30:06 +01:00
|
|
|
|
2025-10-02 16:07:05 +01:00
|
|
|
if (!zoomLevel) return;
|
2025-09-29 08:47:13 +01:00
|
|
|
};
|
|
|
|
|
|
2025-08-13 14:23:48 +01:00
|
|
|
return (
|
2025-09-26 13:38:47 +01:00
|
|
|
<div className="flex flex-col md:flex-row">
|
2025-08-18 12:53:30 +01:00
|
|
|
<NavigationArrow side={side} settingsPage={settingsPage} />
|
2025-09-26 13:38:47 +01:00
|
|
|
<div className="w-full">
|
2025-10-06 14:21:56 +01:00
|
|
|
{isError && <ErrorState />}
|
|
|
|
|
{isPending && (
|
|
|
|
|
<div className="my-50 h-[50%]">
|
|
|
|
|
<Loading message="Camera Preview" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-09-26 13:38:47 +01:00
|
|
|
<canvas
|
2025-09-29 08:47:13 +01:00
|
|
|
onClick={handleZoomClick}
|
2025-09-26 13:38:47 +01:00
|
|
|
ref={canvasRef}
|
|
|
|
|
className="absolute inset-0 object-contain min-h-[100%] z-20"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-08-13 14:23:48 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|