2025-08-13 14:23:48 +01:00
|
|
|
import { useGetOverviewSnapshot } from "../../hooks/useGetOverviewSnapshot";
|
2025-10-01 11:30:06 +01:00
|
|
|
import type { ZoomInOptions, ZoomLevel } from "../../types/types";
|
2025-08-15 09:32:33 +01:00
|
|
|
import NavigationArrow from "../UI/NavigationArrow";
|
2025-10-01 11:30:06 +01:00
|
|
|
import { useCameraZoom } from "../../hooks/useCameraZoom";
|
|
|
|
|
import { useEffect } from "react";
|
2025-08-13 14:23:48 +01:00
|
|
|
|
|
|
|
|
type SnapshotContainerProps = {
|
|
|
|
|
side: string;
|
2025-08-18 12:53:30 +01:00
|
|
|
settingsPage?: boolean;
|
2025-09-29 15:21:22 +01:00
|
|
|
zoomLevel?: ZoomLevel;
|
|
|
|
|
onZoomLevelChange?: (level: ZoomLevel) => void;
|
2025-08-13 14:23:48 +01:00
|
|
|
};
|
|
|
|
|
|
2025-08-18 12:53:30 +01:00
|
|
|
export const SnapshotContainer = ({
|
|
|
|
|
side,
|
|
|
|
|
settingsPage,
|
2025-09-29 15:21:22 +01:00
|
|
|
zoomLevel,
|
|
|
|
|
onZoomLevelChange,
|
2025-08-18 12:53:30 +01:00
|
|
|
}: SnapshotContainerProps) => {
|
2025-09-30 11:11:46 +01:00
|
|
|
const { canvasRef, isError, isPending } = useGetOverviewSnapshot(side);
|
2025-10-01 11:30:06 +01:00
|
|
|
const { mutation } = useCameraZoom();
|
|
|
|
|
const cameraControllerSide =
|
|
|
|
|
side === "CameraA" ? "CameraControllerA" : "CameraControllerB";
|
2025-08-13 14:23:48 +01:00
|
|
|
|
2025-09-29 08:47:13 +01:00
|
|
|
const handleZoomClick = (event: React.MouseEvent<HTMLCanvasElement>) => {
|
|
|
|
|
const bounds = canvasRef.current?.getBoundingClientRect();
|
|
|
|
|
if (!bounds) return;
|
|
|
|
|
const left = bounds.left;
|
|
|
|
|
const top = bounds.top;
|
|
|
|
|
const x = event.pageX;
|
|
|
|
|
const y = event.pageY;
|
|
|
|
|
const cw = canvasRef.current?.clientWidth;
|
|
|
|
|
const ch = canvasRef.current?.clientHeight;
|
|
|
|
|
if (!cw || !ch) return;
|
|
|
|
|
const px = x / cw;
|
|
|
|
|
const py = y / ch;
|
2025-09-29 15:21:22 +01:00
|
|
|
|
|
|
|
|
const baseLevel = zoomLevel?.level ?? 1;
|
|
|
|
|
const newLevel = baseLevel >= 8 ? 1 : baseLevel * 2;
|
|
|
|
|
|
|
|
|
|
if (onZoomLevelChange)
|
|
|
|
|
onZoomLevelChange({
|
|
|
|
|
left,
|
|
|
|
|
top,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
px,
|
|
|
|
|
py,
|
|
|
|
|
level: newLevel,
|
|
|
|
|
});
|
2025-10-01 11:30:06 +01:00
|
|
|
|
|
|
|
|
if (!zoomLevel?.level) return;
|
2025-09-29 08:47:13 +01:00
|
|
|
};
|
|
|
|
|
|
2025-10-01 11:30:06 +01:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (zoomLevel?.level) {
|
|
|
|
|
const zoomInOptions: ZoomInOptions = {
|
|
|
|
|
camera: cameraControllerSide,
|
|
|
|
|
multiplier: zoomLevel.level,
|
|
|
|
|
};
|
|
|
|
|
mutation.mutate(zoomInOptions);
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [zoomLevel?.level]);
|
|
|
|
|
|
|
|
|
|
if (isError) return <p className="h-100">An error occurred</p>;
|
|
|
|
|
if (isPending) return <p className="h-100">Loading...</p>;
|
|
|
|
|
|
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">
|
|
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
};
|