2023-12-08 16:33:22 +03:00
|
|
|
|
import {
|
2024-04-19 14:34:07 +03:00
|
|
|
|
DropdownMenu,
|
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
|
DropdownMenuLabel,
|
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
|
|
import {
|
|
|
|
|
|
AlertDialog,
|
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
|
} from "@/components/ui/alert-dialog";
|
|
|
|
|
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
|
|
|
|
import { Drawer, DrawerContent, DrawerTrigger } from "@/components/ui/drawer";
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2024-04-19 20:17:23 +03:00
|
|
|
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
import useOptimisticState from "@/hooks/use-optimistic-state";
|
2025-03-09 16:47:10 +03:00
|
|
|
|
import { isIOS, isMobile } from "react-device-detect";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
import { FaVideo } from "react-icons/fa";
|
|
|
|
|
|
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
import FilterSwitch from "@/components/filter/FilterSwitch";
|
|
|
|
|
|
import { ZoneMaskFilterButton } from "@/components/filter/ZoneMaskFilter";
|
|
|
|
|
|
import { PolygonType } from "@/types/canvas";
|
2024-04-19 20:17:23 +03:00
|
|
|
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
|
|
|
|
|
import scrollIntoView from "scroll-into-view-if-needed";
|
2024-07-12 16:42:53 +03:00
|
|
|
|
import CameraSettingsView from "@/views/settings/CameraSettingsView";
|
2024-05-29 17:01:39 +03:00
|
|
|
|
import ObjectSettingsView from "@/views/settings/ObjectSettingsView";
|
|
|
|
|
|
import MotionTunerView from "@/views/settings/MotionTunerView";
|
|
|
|
|
|
import MasksAndZonesView from "@/views/settings/MasksAndZonesView";
|
|
|
|
|
|
import AuthenticationView from "@/views/settings/AuthenticationView";
|
2024-07-22 23:39:15 +03:00
|
|
|
|
import NotificationView from "@/views/settings/NotificationsSettingsView";
|
2025-03-14 19:23:37 +03:00
|
|
|
|
import ClassificationSettingsView from "@/views/settings/ClassificationSettingsView";
|
2024-10-16 03:25:59 +03:00
|
|
|
|
import UiSettingsView from "@/views/settings/UiSettingsView";
|
2025-03-17 21:44:57 +03:00
|
|
|
|
import FrigatePlusSettingsView from "@/views/settings/FrigatePlusSettingsView";
|
2025-02-10 19:42:35 +03:00
|
|
|
|
import { useSearchEffect } from "@/hooks/use-overlay-state";
|
2025-02-15 16:56:45 +03:00
|
|
|
|
import { useSearchParams } from "react-router-dom";
|
2025-03-03 18:30:52 +03:00
|
|
|
|
import { useInitialCameraState } from "@/api/ws";
|
2025-03-08 19:13:07 +03:00
|
|
|
|
import { isInIframe } from "@/utils/isIFrame";
|
|
|
|
|
|
import { isPWA } from "@/utils/isPWA";
|
2025-03-08 19:01:08 +03:00
|
|
|
|
import { useIsAdmin } from "@/hooks/use-is-admin";
|
2025-03-16 18:36:20 +03:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
2024-07-22 23:39:15 +03:00
|
|
|
|
|
|
|
|
|
|
const allSettingsViews = [
|
2025-03-21 20:47:32 +03:00
|
|
|
|
"ui",
|
|
|
|
|
|
"classification",
|
|
|
|
|
|
"cameras",
|
2025-03-16 18:36:20 +03:00
|
|
|
|
"masksAndZones",
|
|
|
|
|
|
"motionTuner",
|
2024-07-22 23:39:15 +03:00
|
|
|
|
"debug",
|
|
|
|
|
|
"users",
|
|
|
|
|
|
"notifications",
|
2025-03-17 21:44:57 +03:00
|
|
|
|
"frigateplus",
|
2024-07-22 23:39:15 +03:00
|
|
|
|
] as const;
|
|
|
|
|
|
type SettingsType = (typeof allSettingsViews)[number];
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
|
|
|
|
|
export default function Settings() {
|
2025-03-16 18:36:20 +03:00
|
|
|
|
const { t } = useTranslation(["views/settings"]);
|
2025-03-21 20:47:32 +03:00
|
|
|
|
const [page, setPage] = useState<SettingsType>("ui");
|
2024-04-19 14:34:07 +03:00
|
|
|
|
const [pageToggle, setPageToggle] = useOptimisticState(page, setPage, 100);
|
2024-04-19 20:17:23 +03:00
|
|
|
|
const tabsRef = useRef<HTMLDivElement | null>(null);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
|
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
|
2025-02-15 16:56:45 +03:00
|
|
|
|
const [searchParams] = useSearchParams();
|
|
|
|
|
|
|
2025-03-08 19:01:08 +03:00
|
|
|
|
// auth and roles
|
|
|
|
|
|
|
|
|
|
|
|
const isAdmin = useIsAdmin();
|
|
|
|
|
|
|
2025-03-21 20:47:32 +03:00
|
|
|
|
const allowedViewsForViewer: SettingsType[] = ["ui", "debug"];
|
2025-03-08 19:01:08 +03:00
|
|
|
|
const visibleSettingsViews = !isAdmin
|
|
|
|
|
|
? allowedViewsForViewer
|
|
|
|
|
|
: allSettingsViews;
|
|
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
// TODO: confirm leave page
|
|
|
|
|
|
const [unsavedChanges, setUnsavedChanges] = useState(false);
|
|
|
|
|
|
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
const cameras = useMemo(() => {
|
|
|
|
|
|
if (!config) {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Object.values(config.cameras)
|
2025-03-03 18:30:52 +03:00
|
|
|
|
.filter((conf) => conf.ui.dashboard && conf.enabled_in_config)
|
2024-04-19 14:34:07 +03:00
|
|
|
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
|
|
|
|
|
}, [config]);
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedCamera, setSelectedCamera] = useState<string>("");
|
|
|
|
|
|
|
2025-03-03 18:30:52 +03:00
|
|
|
|
const { payload: allCameraStates } = useInitialCameraState(
|
|
|
|
|
|
cameras.length > 0 ? cameras[0].name : "",
|
|
|
|
|
|
true,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const cameraEnabledStates = useMemo(() => {
|
|
|
|
|
|
const states: Record<string, boolean> = {};
|
|
|
|
|
|
if (allCameraStates) {
|
|
|
|
|
|
Object.entries(allCameraStates).forEach(([camName, state]) => {
|
|
|
|
|
|
states[camName] = state.config?.enabled ?? false;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
// fallback to config if ws data isn’t available yet
|
|
|
|
|
|
cameras.forEach((cam) => {
|
|
|
|
|
|
if (!(cam.name in states)) {
|
|
|
|
|
|
states[cam.name] = cam.enabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return states;
|
|
|
|
|
|
}, [allCameraStates, cameras]);
|
|
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
const [filterZoneMask, setFilterZoneMask] = useState<PolygonType[]>();
|
|
|
|
|
|
|
|
|
|
|
|
const handleDialog = useCallback(
|
|
|
|
|
|
(save: boolean) => {
|
|
|
|
|
|
if (unsavedChanges && save) {
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
}
|
|
|
|
|
|
setConfirmationDialogOpen(false);
|
|
|
|
|
|
setUnsavedChanges(false);
|
|
|
|
|
|
},
|
|
|
|
|
|
[unsavedChanges],
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-03-03 18:30:52 +03:00
|
|
|
|
if (cameras.length > 0) {
|
|
|
|
|
|
if (!selectedCamera) {
|
|
|
|
|
|
// Set to first enabled camera initially if no selection
|
|
|
|
|
|
const firstEnabledCamera =
|
|
|
|
|
|
cameras.find((cam) => cameraEnabledStates[cam.name]) || cameras[0];
|
|
|
|
|
|
setSelectedCamera(firstEnabledCamera.name);
|
2025-03-21 20:47:32 +03:00
|
|
|
|
} else if (!cameraEnabledStates[selectedCamera] && page !== "cameras") {
|
2025-03-03 18:30:52 +03:00
|
|
|
|
// Switch to first enabled camera if current one is disabled, unless on "camera settings" page
|
|
|
|
|
|
const firstEnabledCamera =
|
|
|
|
|
|
cameras.find((cam) => cameraEnabledStates[cam.name]) || cameras[0];
|
|
|
|
|
|
if (firstEnabledCamera.name !== selectedCamera) {
|
|
|
|
|
|
setSelectedCamera(firstEnabledCamera.name);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
}
|
2025-03-03 18:30:52 +03:00
|
|
|
|
}, [cameras, selectedCamera, cameraEnabledStates, page]);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2024-04-19 20:17:23 +03:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (tabsRef.current) {
|
|
|
|
|
|
const element = tabsRef.current.querySelector(
|
|
|
|
|
|
`[data-nav-item="${pageToggle}"]`,
|
|
|
|
|
|
);
|
|
|
|
|
|
if (element instanceof HTMLElement) {
|
|
|
|
|
|
scrollIntoView(element, {
|
2025-03-09 16:47:10 +03:00
|
|
|
|
behavior:
|
|
|
|
|
|
isMobile && isIOS && !isPWA && isInIframe ? "auto" : "smooth",
|
2024-04-19 20:17:23 +03:00
|
|
|
|
inline: "start",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [tabsRef, pageToggle]);
|
|
|
|
|
|
|
2025-02-10 19:42:35 +03:00
|
|
|
|
useSearchEffect("page", (page: string) => {
|
|
|
|
|
|
if (allSettingsViews.includes(page as SettingsType)) {
|
2025-03-08 19:01:08 +03:00
|
|
|
|
// Restrict viewer to UI settings
|
2025-03-21 20:47:32 +03:00
|
|
|
|
if (!isAdmin && !["ui", "debug"].includes(page)) {
|
|
|
|
|
|
setPage("ui");
|
2025-03-08 19:01:08 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
setPage(page as SettingsType);
|
|
|
|
|
|
}
|
2025-02-10 19:42:35 +03:00
|
|
|
|
}
|
2025-02-15 16:56:45 +03:00
|
|
|
|
// don't clear url params if we're creating a new object mask
|
|
|
|
|
|
return !searchParams.has("object_mask");
|
2025-02-10 19:42:35 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
useSearchEffect("camera", (camera: string) => {
|
|
|
|
|
|
const cameraNames = cameras.map((c) => c.name);
|
|
|
|
|
|
if (cameraNames.includes(camera)) {
|
|
|
|
|
|
setSelectedCamera(camera);
|
|
|
|
|
|
}
|
2025-02-15 16:56:45 +03:00
|
|
|
|
// don't clear url params if we're creating a new object mask
|
|
|
|
|
|
return !searchParams.has("object_mask");
|
2025-02-10 19:42:35 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2024-04-27 20:02:01 +03:00
|
|
|
|
useEffect(() => {
|
2025-03-16 18:36:20 +03:00
|
|
|
|
document.title = t("documentTitle.default");
|
|
|
|
|
|
}, [t]);
|
2024-04-27 20:02:01 +03:00
|
|
|
|
|
2023-12-08 16:33:22 +03:00
|
|
|
|
return (
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="flex size-full flex-col p-2">
|
|
|
|
|
|
<div className="relative flex h-11 w-full items-center justify-between">
|
2024-04-19 20:17:23 +03:00
|
|
|
|
<ScrollArea className="w-full whitespace-nowrap">
|
|
|
|
|
|
<div ref={tabsRef} className="flex flex-row">
|
|
|
|
|
|
<ToggleGroup
|
2024-05-14 18:06:44 +03:00
|
|
|
|
className="*:rounded-md *:px-3 *:py-4"
|
2024-04-19 20:17:23 +03:00
|
|
|
|
type="single"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
value={pageToggle}
|
|
|
|
|
|
onValueChange={(value: SettingsType) => {
|
|
|
|
|
|
if (value) {
|
2025-03-08 19:01:08 +03:00
|
|
|
|
// Restrict viewer navigation
|
2025-03-21 20:47:32 +03:00
|
|
|
|
if (!isAdmin && !["ui", "debug"].includes(value)) {
|
|
|
|
|
|
setPageToggle("ui");
|
2025-03-08 19:01:08 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
setPageToggle(value);
|
|
|
|
|
|
}
|
2024-04-19 20:17:23 +03:00
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2025-03-08 19:01:08 +03:00
|
|
|
|
{visibleSettingsViews.map((item) => (
|
2024-04-19 20:17:23 +03:00
|
|
|
|
<ToggleGroupItem
|
|
|
|
|
|
key={item}
|
2025-03-21 20:47:32 +03:00
|
|
|
|
className={`flex scroll-mx-10 items-center justify-between gap-2 ${page == "ui" ? "last:mr-20" : ""} ${pageToggle == item ? "" : "*:text-muted-foreground"}`}
|
2024-04-19 20:17:23 +03:00
|
|
|
|
value={item}
|
|
|
|
|
|
data-nav-item={item}
|
2025-03-16 18:36:20 +03:00
|
|
|
|
aria-label={t("selectItem", {
|
|
|
|
|
|
ns: "common",
|
2025-03-17 15:26:01 +03:00
|
|
|
|
item: t("menu." + item),
|
2025-03-16 18:36:20 +03:00
|
|
|
|
})}
|
2024-04-19 20:17:23 +03:00
|
|
|
|
>
|
2025-04-23 01:21:09 +03:00
|
|
|
|
<div className="smart-capitalize">{t("menu." + item)}</div>
|
2024-04-19 20:17:23 +03:00
|
|
|
|
</ToggleGroupItem>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</ToggleGroup>
|
|
|
|
|
|
<ScrollBar orientation="horizontal" className="h-0" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</ScrollArea>
|
2024-05-01 17:07:56 +03:00
|
|
|
|
{(page == "debug" ||
|
2025-03-21 20:47:32 +03:00
|
|
|
|
page == "cameras" ||
|
2025-03-16 18:36:20 +03:00
|
|
|
|
page == "masksAndZones" ||
|
|
|
|
|
|
page == "motionTuner") && (
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="ml-2 flex flex-shrink-0 items-center gap-2">
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{page == "masksAndZones" && (
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<ZoneMaskFilterButton
|
|
|
|
|
|
selectedZoneMask={filterZoneMask}
|
|
|
|
|
|
updateZoneMaskFilter={setFilterZoneMask}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
<CameraSelectButton
|
|
|
|
|
|
allCameras={cameras}
|
|
|
|
|
|
selectedCamera={selectedCamera}
|
|
|
|
|
|
setSelectedCamera={setSelectedCamera}
|
2025-03-03 18:30:52 +03:00
|
|
|
|
cameraEnabledStates={cameraEnabledStates}
|
|
|
|
|
|
currentPage={page}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="mt-2 flex h-full w-full flex-col items-start md:h-dvh md:pb-24">
|
2025-03-21 20:47:32 +03:00
|
|
|
|
{page == "ui" && <UiSettingsView />}
|
|
|
|
|
|
{page == "classification" && (
|
2025-03-14 19:23:37 +03:00
|
|
|
|
<ClassificationSettingsView setUnsavedChanges={setUnsavedChanges} />
|
2024-10-16 03:25:59 +03:00
|
|
|
|
)}
|
2024-05-29 17:01:39 +03:00
|
|
|
|
{page == "debug" && (
|
|
|
|
|
|
<ObjectSettingsView selectedCamera={selectedCamera} />
|
|
|
|
|
|
)}
|
2025-03-21 20:47:32 +03:00
|
|
|
|
{page == "cameras" && (
|
2024-07-12 16:42:53 +03:00
|
|
|
|
<CameraSettingsView
|
|
|
|
|
|
selectedCamera={selectedCamera}
|
|
|
|
|
|
setUnsavedChanges={setUnsavedChanges}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{page == "masksAndZones" && (
|
2024-05-29 17:01:39 +03:00
|
|
|
|
<MasksAndZonesView
|
2024-04-19 14:34:07 +03:00
|
|
|
|
selectedCamera={selectedCamera}
|
|
|
|
|
|
selectedZoneMask={filterZoneMask}
|
|
|
|
|
|
setUnsavedChanges={setUnsavedChanges}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{page == "motionTuner" && (
|
2024-05-29 17:01:39 +03:00
|
|
|
|
<MotionTunerView
|
2024-04-19 14:34:07 +03:00
|
|
|
|
selectedCamera={selectedCamera}
|
|
|
|
|
|
setUnsavedChanges={setUnsavedChanges}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2024-05-29 17:01:39 +03:00
|
|
|
|
{page == "users" && <AuthenticationView />}
|
2024-07-22 23:39:15 +03:00
|
|
|
|
{page == "notifications" && (
|
|
|
|
|
|
<NotificationView setUnsavedChanges={setUnsavedChanges} />
|
|
|
|
|
|
)}
|
2025-03-24 18:19:58 +03:00
|
|
|
|
{page == "frigateplus" && (
|
|
|
|
|
|
<FrigatePlusSettingsView setUnsavedChanges={setUnsavedChanges} />
|
|
|
|
|
|
)}
|
2023-12-08 16:33:22 +03:00
|
|
|
|
</div>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
{confirmationDialogOpen && (
|
|
|
|
|
|
<AlertDialog
|
|
|
|
|
|
open={confirmationDialogOpen}
|
|
|
|
|
|
onOpenChange={() => setConfirmationDialogOpen(false)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
|
<AlertDialogHeader>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
<AlertDialogTitle>
|
|
|
|
|
|
{t("dialog.unsavedChanges.title")}
|
|
|
|
|
|
</AlertDialogTitle>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<AlertDialogDescription>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{t("dialog.unsavedChanges.desc")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
|
<AlertDialogCancel onClick={() => handleDialog(false)}>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{t("button.cancel", { ns: "common" })}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</AlertDialogCancel>
|
|
|
|
|
|
<AlertDialogAction onClick={() => handleDialog(true)}>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{t("button.save", { ns: "common" })}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type CameraSelectButtonProps = {
|
|
|
|
|
|
allCameras: CameraConfig[];
|
|
|
|
|
|
selectedCamera: string;
|
|
|
|
|
|
setSelectedCamera: React.Dispatch<React.SetStateAction<string>>;
|
2025-03-03 18:30:52 +03:00
|
|
|
|
cameraEnabledStates: Record<string, boolean>;
|
|
|
|
|
|
currentPage: SettingsType;
|
2024-04-19 14:34:07 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function CameraSelectButton({
|
|
|
|
|
|
allCameras,
|
|
|
|
|
|
selectedCamera,
|
|
|
|
|
|
setSelectedCamera,
|
2025-03-03 18:30:52 +03:00
|
|
|
|
cameraEnabledStates,
|
|
|
|
|
|
currentPage,
|
2024-04-19 14:34:07 +03:00
|
|
|
|
}: CameraSelectButtonProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
|
const { t } = useTranslation(["views/settings"]);
|
|
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
const [open, setOpen] = useState(false);
|
2023-12-08 16:33:22 +03:00
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
if (!allCameras.length) {
|
2025-03-03 18:30:52 +03:00
|
|
|
|
return null;
|
2024-04-19 14:34:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const trigger = (
|
|
|
|
|
|
<Button
|
2025-04-23 01:21:09 +03:00
|
|
|
|
className="flex items-center gap-2 bg-selected smart-capitalize hover:bg-selected"
|
2024-10-23 01:07:42 +03:00
|
|
|
|
aria-label="Select a camera"
|
2024-04-19 14:34:07 +03:00
|
|
|
|
size="sm"
|
|
|
|
|
|
>
|
|
|
|
|
|
<FaVideo className="text-background dark:text-primary" />
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="hidden text-background dark:text-primary md:block">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
{selectedCamera == undefined
|
2025-03-16 18:36:20 +03:00
|
|
|
|
? t("cameraSetting.noCamera")
|
2024-04-19 14:34:07 +03:00
|
|
|
|
: selectedCamera.replaceAll("_", " ")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
);
|
|
|
|
|
|
const content = (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{isMobile && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<DropdownMenuLabel className="flex justify-center">
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{t("cameraSetting.camera")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</DropdownMenuLabel>
|
|
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-06-03 21:43:30 +03:00
|
|
|
|
<div className="scrollbar-container mb-5 h-auto max-h-[80dvh] overflow-y-auto overflow-x-hidden p-4 md:mb-1">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<div className="flex flex-col gap-2.5">
|
2025-03-03 18:30:52 +03:00
|
|
|
|
{allCameras.map((item) => {
|
|
|
|
|
|
const isEnabled = cameraEnabledStates[item.name];
|
2025-03-21 20:47:32 +03:00
|
|
|
|
const isCameraSettingsPage = currentPage === "cameras";
|
2025-03-03 18:30:52 +03:00
|
|
|
|
return (
|
|
|
|
|
|
<FilterSwitch
|
|
|
|
|
|
key={item.name}
|
|
|
|
|
|
isChecked={item.name === selectedCamera}
|
|
|
|
|
|
label={item.name.replaceAll("_", " ")}
|
|
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
|
|
if (isChecked && (isEnabled || isCameraSettingsPage)) {
|
|
|
|
|
|
setSelectedCamera(item.name);
|
|
|
|
|
|
setOpen(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
disabled={!isEnabled && !isCameraSettingsPage}
|
|
|
|
|
|
/>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</div>
|
2023-12-08 16:33:22 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
if (isMobile) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Drawer
|
|
|
|
|
|
open={open}
|
|
|
|
|
|
onOpenChange={(open: boolean) => {
|
|
|
|
|
|
if (!open) {
|
|
|
|
|
|
setSelectedCamera(selectedCamera);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setOpen(open);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<DrawerTrigger asChild>{trigger}</DrawerTrigger>
|
|
|
|
|
|
<DrawerContent className="max-h-[75dvh] overflow-hidden">
|
|
|
|
|
|
{content}
|
|
|
|
|
|
</DrawerContent>
|
|
|
|
|
|
</Drawer>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<DropdownMenu
|
2024-05-30 16:39:14 +03:00
|
|
|
|
modal={false}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
open={open}
|
|
|
|
|
|
onOpenChange={(open: boolean) => {
|
|
|
|
|
|
if (!open) {
|
|
|
|
|
|
setSelectedCamera(selectedCamera);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setOpen(open);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<DropdownMenuTrigger asChild>{trigger}</DropdownMenuTrigger>
|
|
|
|
|
|
<DropdownMenuContent>{content}</DropdownMenuContent>
|
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|