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"; import NumberPlate from "../PlateStack/NumberPlate"; import Loading from "../UI/Loading"; const SightingOverview = () => { const [overlayMode, setOverlayMode] = useState<0 | 1 | 2>(0); const imgRef = useRef(null); const canvasRef = useRef(null); const onOverviewClick = useCallback(() => { setOverlayMode((m) => ((m + 1) % 3) as 0 | 1 | 2); }, []); const { side, mostRecent, isError, isLoading } = useSightingFeedContext(); useOverviewOverlay(mostRecent, overlayMode, imgRef, canvasRef); const { sync } = useHiDPICanvas(imgRef, canvasRef); if (isLoading) return (
); if (isError) return;
An error occurred. Cannot display footage.
; if (!mostRecent) return (
); return (
{mostRecent && (
)} { 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", }} />
); }; export default SightingOverview;