mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 20:25:26 +03:00
Add saving of camera group selection
This commit is contained in:
parent
48c51545af
commit
0d6ebcdba8
66
web/src/components/filter/CameraGroupSelector.tsx
Normal file
66
web/src/components/filter/CameraGroupSelector.tsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
|
import { isMobile } from "react-device-detect";
|
||||||
|
import useSWR from "swr";
|
||||||
|
import { MdHome } from "react-icons/md";
|
||||||
|
import { FaCar, FaCircle, FaLeaf } from "react-icons/fa";
|
||||||
|
import useOverlayState from "@/hooks/use-overlay-state";
|
||||||
|
import { Button } from "../ui/button";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
export function CameraGroupSelector() {
|
||||||
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [group, setGroup] = useOverlayState("cameraGroup");
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-start gap-2">
|
||||||
|
<Button
|
||||||
|
className={
|
||||||
|
group == undefined
|
||||||
|
? "text-selected bg-blue-900 focus:bg-blue-900 bg-opacity-60 focus:bg-opacity-60"
|
||||||
|
: "text-muted-foreground bg-muted"
|
||||||
|
}
|
||||||
|
size="xs"
|
||||||
|
onClick={() => navigate(-1)}
|
||||||
|
>
|
||||||
|
<MdHome className="size-4" />
|
||||||
|
</Button>
|
||||||
|
{Object.entries(config?.camera_groups ?? {}).map(([name, config]) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
key={name}
|
||||||
|
className={
|
||||||
|
group == name
|
||||||
|
? "text-selected bg-blue-900 focus:bg-blue-900 bg-opacity-60 focus:bg-opacity-60"
|
||||||
|
: "text-muted-foreground bg-muted"
|
||||||
|
}
|
||||||
|
size="xs"
|
||||||
|
onClick={() => setGroup(name)}
|
||||||
|
>
|
||||||
|
{getGroupIcon(config.icon)}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div></div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroupIcon(icon: string) {
|
||||||
|
switch (icon) {
|
||||||
|
case "car":
|
||||||
|
return <FaCar className="size-4" />;
|
||||||
|
case "leaf":
|
||||||
|
return <FaLeaf className="size-4" />;
|
||||||
|
default:
|
||||||
|
return <FaCircle className="size-4" />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {config &&
|
||||||
|
}
|
||||||
|
*/
|
||||||
@ -22,7 +22,7 @@ const buttonVariants = cva(
|
|||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: "h-10 px-4 py-2",
|
default: "h-10 px-4 py-2",
|
||||||
xs: "h-6 rounded-md",
|
xs: "size-6 rounded-md",
|
||||||
sm: "h-9 rounded-md px-3",
|
sm: "h-9 rounded-md px-3",
|
||||||
lg: "h-11 rounded-md px-8",
|
lg: "h-11 rounded-md px-8",
|
||||||
icon: "h-10 w-10",
|
icon: "h-10 w-10",
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export default function useOverlayState(key: string) {
|
export default function useOverlayState(
|
||||||
|
key: string,
|
||||||
|
): [string | undefined, (value: string) => void] {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const currentLocationState = location.state;
|
const currentLocationState = location.state;
|
||||||
@ -17,6 +19,10 @@ export default function useOverlayState(key: string) {
|
|||||||
[key, navigate],
|
[key, navigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const overlayStateValue = location.state && location.state[key];
|
const overlayStateValue = useMemo<string | undefined>(
|
||||||
|
() => location.state && location.state[key],
|
||||||
|
[location, key],
|
||||||
|
);
|
||||||
|
|
||||||
return [overlayStateValue, setOverlayStateValue];
|
return [overlayStateValue, setOverlayStateValue];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user