import { Stage, Layer, Image, Rect } from "react-konva"; import type { SightingType } from "../../../../utils/types"; import { useCreateVideoSnapshot } from "../../hooks/useCreateVideoSnapshot"; import { useEffect, useState } from "react"; import { useCameraSettingsContext } from "../../../../app/context/CameraSettingsContext"; type VideoFeedProps = { mostRecentSighting: SightingType; isLoading: boolean; }; const VideoFeed = ({ mostRecentSighting, isLoading }: VideoFeedProps) => { const { state: cameraSettings, dispatch } = useCameraSettingsContext(); const mode = cameraSettings.mode; const [size, setSize] = useState<{ width: number; height: number }>({ width: 1280, height: 960 }); const { image, plateRect, plateTrack } = useCreateVideoSnapshot(mostRecentSighting); const handleModeChange = (newMode: number) => { if (newMode > 2) dispatch({ type: "SET_MODE", payload: 0 }); else dispatch({ type: "SET_MODE", payload: newMode }); }; useEffect(() => { const updateSize = () => { const width = window.innerWidth * 0.48; const height = (width * 2) / 3; setSize({ width, height }); }; updateSize(); window.addEventListener("resize", updateSize); return () => window.removeEventListener("resize", updateSize); }, []); if (isLoading) return <>Loading...; return (
handleModeChange(mode + 1)}> { const container = e.target.getStage()?.container(); if (container) container.style.cursor = "pointer"; }} onMouseLeave={(e) => { const container = e.target.getStage()?.container(); if (container) container.style.cursor = "default"; }} cornerRadius={10} /> {plateRect && mode === 1 && ( )} {plateTrack && mode === 2 && ( {plateTrack.map((rect, index) => ( ))} )}
); }; export default VideoFeed;