2025-08-20 08:27:05 +01:00
|
|
|
import { useCallback, useRef, useState } from "react";
|
|
|
|
|
import { BLANK_IMG } from "../../utils/utils";
|
|
|
|
|
import { useOverviewOverlay } from "../../hooks/useOverviewOverlay";
|
|
|
|
|
import { useSightingFeedContext } from "../../context/SightingFeedContext";
|
|
|
|
|
import { useHiDPICanvas } from "../../hooks/useHiDPICanvas";
|
|
|
|
|
import NavigationArrow from "../UI/NavigationArrow";
|
2025-09-26 11:42:12 +01:00
|
|
|
import NumberPlate from "../PlateStack/NumberPlate";
|
2025-08-20 08:27:05 +01:00
|
|
|
|
|
|
|
|
const SightingOverview = () => {
|
|
|
|
|
const [overlayMode, setOverlayMode] = useState<0 | 1 | 2>(0);
|
|
|
|
|
|
|
|
|
|
const imgRef = useRef<HTMLImageElement | null>(null);
|
|
|
|
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
|
|
|
|
|
|
|
|
const onOverviewClick = useCallback(() => {
|
|
|
|
|
setOverlayMode((m) => ((m + 1) % 3) as 0 | 1 | 2);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-09-17 11:39:26 +01:00
|
|
|
const { side, mostRecent, isError, isLoading } = useSightingFeedContext();
|
2025-08-20 08:27:05 +01:00
|
|
|
|
2025-08-22 10:38:28 +01:00
|
|
|
useOverviewOverlay(mostRecent, overlayMode, imgRef, canvasRef);
|
2025-08-20 08:27:05 +01:00
|
|
|
|
|
|
|
|
const { sync } = useHiDPICanvas(imgRef, canvasRef);
|
2025-08-29 14:55:37 +01:00
|
|
|
|
2025-09-17 11:39:26 +01:00
|
|
|
if (isLoading) return <p>Loading</p>;
|
|
|
|
|
|
|
|
|
|
if (isError) return <p>An error occurred, Cannot display footage</p>;
|
2025-09-12 08:21:52 +01:00
|
|
|
|
2025-08-20 08:27:05 +01:00
|
|
|
return (
|
2025-09-26 11:42:12 +01:00
|
|
|
<div className="flex flex-col md:flex-row">
|
|
|
|
|
<NavigationArrow side={side} />
|
|
|
|
|
<div className="w-full">
|
2025-09-26 14:47:34 +01:00
|
|
|
{mostRecent && (
|
|
|
|
|
<div className="absolute inset-0 z-50 px-1 pt-2">
|
|
|
|
|
<NumberPlate vrm={mostRecent?.vrm} size="sm" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-09-26 11:42:12 +01:00
|
|
|
<img
|
|
|
|
|
ref={imgRef}
|
|
|
|
|
onLoad={() => {
|
|
|
|
|
sync();
|
|
|
|
|
setOverlayMode((m) => m);
|
|
|
|
|
}}
|
|
|
|
|
src={mostRecent?.overviewUrl || BLANK_IMG}
|
|
|
|
|
alt="overview"
|
|
|
|
|
className="absolute inset-0 object-contain cursor-pointer z-10 min-h-[100%] rounded-lg"
|
|
|
|
|
onClick={onOverviewClick}
|
|
|
|
|
style={{
|
|
|
|
|
display: mostRecent?.overviewUrl ? "block" : "none",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<canvas
|
|
|
|
|
ref={canvasRef}
|
|
|
|
|
className="absolute inset-0 object-contain z-20 pointer-events-none "
|
|
|
|
|
/>
|
2025-08-20 08:27:05 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SightingOverview;
|