2025-08-20 08:27:05 +01:00
|
|
|
import { useCallback, useRef, useState } from "react";
|
|
|
|
|
import { BLANK_IMG } from "../../utils/utils";
|
|
|
|
|
import SightingWidgetDetails from "../SightingsWidget/SightingWidgetDetails";
|
|
|
|
|
import { useOverviewOverlay } from "../../hooks/useOverviewOverlay";
|
|
|
|
|
import { useSightingFeedContext } from "../../context/SightingFeedContext";
|
|
|
|
|
import { useHiDPICanvas } from "../../hooks/useHiDPICanvas";
|
|
|
|
|
import NavigationArrow from "../UI/NavigationArrow";
|
2025-08-22 10:38:28 +01:00
|
|
|
import { useSwipeable } from "react-swipeable";
|
|
|
|
|
import { useNavigate } from "react-router";
|
2025-08-20 08:27:05 +01:00
|
|
|
|
|
|
|
|
const SightingOverview = () => {
|
2025-08-22 10:38:28 +01:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const handlers = useSwipeable({
|
|
|
|
|
onSwipedRight: () => navigate("/front-camera-settings"),
|
|
|
|
|
trackMouse: true,
|
|
|
|
|
});
|
2025-08-20 08:27:05 +01:00
|
|
|
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-08-22 10:38:28 +01:00
|
|
|
const { effectiveSelected, side, mostRecent, noSighting } =
|
|
|
|
|
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-22 10:38:28 +01:00
|
|
|
if (noSighting) return <p>loading</p>;
|
2025-08-20 08:27:05 +01:00
|
|
|
return (
|
|
|
|
|
<div className="mt-2 grid gap-3">
|
2025-08-22 10:38:28 +01:00
|
|
|
<div className="inline-block w-[90%] mx-auto" {...handlers}>
|
|
|
|
|
<NavigationArrow side={side} />
|
2025-08-20 08:27:05 +01:00
|
|
|
<div className="relative aspect-[5/4]">
|
|
|
|
|
<img
|
|
|
|
|
ref={imgRef}
|
|
|
|
|
onLoad={() => {
|
|
|
|
|
sync();
|
|
|
|
|
setOverlayMode((m) => m);
|
|
|
|
|
}}
|
2025-08-22 10:38:28 +01:00
|
|
|
src={mostRecent?.overviewUrl || BLANK_IMG}
|
2025-08-20 08:27:05 +01:00
|
|
|
alt="overview"
|
|
|
|
|
className="absolute inset-0 w-full h-full object-contain cursor-pointer z-10"
|
|
|
|
|
onClick={onOverviewClick}
|
|
|
|
|
style={{
|
2025-08-22 10:38:28 +01:00
|
|
|
display: mostRecent?.overviewUrl ? "block" : "none",
|
2025-08-20 08:27:05 +01:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<canvas
|
|
|
|
|
ref={canvasRef}
|
|
|
|
|
className="absolute inset-0 w-full h-full object-contain z-20 pointer-events-none"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<SightingWidgetDetails effectiveSelected={effectiveSelected} />
|
|
|
|
|
|
|
|
|
|
<div className="text-xs opacity-80">
|
|
|
|
|
Overlay:{" "}
|
|
|
|
|
{overlayMode === 0
|
|
|
|
|
? "Off"
|
|
|
|
|
: overlayMode === 1
|
|
|
|
|
? "Plate box"
|
|
|
|
|
: "Track + box"}{" "}
|
|
|
|
|
(click image to toggle)
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SightingOverview;
|