mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-01-02 00:07:11 +01:00
5f15641b1b
* initial working konva * working multi polygons * multi zones * clean up * new zone dialog * clean up * relative coordinates and colors * fix color order * better motion tuner * objects for zones * progress * merge dev * edit pane * motion and object masks * filtering * add objects and unsaved to type * motion tuner, edit controls, tooltips * object and motion edit panes * polygon item component, switch color, object form, hover cards * working zone edit pane * working motion masks * object masks and deletion of all types * use FilterSwitch * motion tuner fixes and tweaks * clean up * tweaks * spaces in camera name * tweaks * allow dragging of points while drawing polygon * turn off editing mode when switching camera * limit interpolated coordinates and use crosshair cursor * padding * fix tooltip trigger for icons * konva tweaks * consolidate * fix top menu items on mobile
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { useApiHost } from "@/api";
|
|
import { useEffect, useRef, useState } from "react";
|
|
import useSWR from "swr";
|
|
import ActivityIndicator from "../indicators/activity-indicator";
|
|
|
|
type CameraImageProps = {
|
|
className?: string;
|
|
camera: string;
|
|
onload?: () => void;
|
|
searchParams?: string;
|
|
};
|
|
|
|
export default function CameraImage({
|
|
className,
|
|
camera,
|
|
onload,
|
|
searchParams = "",
|
|
}: CameraImageProps) {
|
|
const { data: config } = useSWR("config");
|
|
const apiHost = useApiHost();
|
|
const [hasLoaded, setHasLoaded] = useState(false);
|
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
const imgRef = useRef<HTMLImageElement | null>(null);
|
|
|
|
const { name } = config ? config.cameras[camera] : "";
|
|
const enabled = config ? config.cameras[camera].enabled : "True";
|
|
|
|
useEffect(() => {
|
|
if (!config || !imgRef.current) {
|
|
return;
|
|
}
|
|
|
|
imgRef.current.src = `${apiHost}api/${name}/latest.jpg${
|
|
searchParams ? `?${searchParams}` : ""
|
|
}`;
|
|
}, [apiHost, name, imgRef, searchParams, config]);
|
|
|
|
return (
|
|
<div className={className} ref={containerRef}>
|
|
{enabled ? (
|
|
<img
|
|
ref={imgRef}
|
|
className="object-contain rounded-2xl"
|
|
onLoad={() => {
|
|
setHasLoaded(true);
|
|
|
|
if (onload) {
|
|
onload();
|
|
}
|
|
}}
|
|
/>
|
|
) : (
|
|
<div className="text-center pt-6">
|
|
Camera is disabled in config, no stream or snapshot available!
|
|
</div>
|
|
)}
|
|
{!hasLoaded && enabled ? (
|
|
<div className="absolute left-0 right-0 top-0 bottom-0 flex justify-center items-center">
|
|
<ActivityIndicator />
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|