mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
Only show frigate+ page when frigate+ is enabled
This commit is contained in:
parent
975007a645
commit
360a6a68b4
@ -1,4 +1,3 @@
|
|||||||
import { navbarLinks } from "@/pages/site-navigation";
|
|
||||||
import NavItem from "./NavItem";
|
import NavItem from "./NavItem";
|
||||||
import { IoIosWarning } from "react-icons/io";
|
import { IoIosWarning } from "react-icons/io";
|
||||||
import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer";
|
import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer";
|
||||||
@ -9,20 +8,15 @@ import { useMemo } from "react";
|
|||||||
import useStats from "@/hooks/use-stats";
|
import useStats from "@/hooks/use-stats";
|
||||||
import GeneralSettings from "../settings/GeneralSettings";
|
import GeneralSettings from "../settings/GeneralSettings";
|
||||||
import AccountSettings from "../settings/AccountSettings";
|
import AccountSettings from "../settings/AccountSettings";
|
||||||
|
import useNavigation from "@/hooks/use-navigation";
|
||||||
|
|
||||||
function Bottombar() {
|
function Bottombar() {
|
||||||
|
const navItems = useNavigation("secondary");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute h-16 inset-x-4 bottom-0 flex flex-row items-center justify-between">
|
<div className="absolute h-16 inset-x-4 bottom-0 flex flex-row items-center justify-between">
|
||||||
{navbarLinks.map((item) => (
|
{navItems.map((item) => (
|
||||||
<NavItem
|
<NavItem key={item.id} item={item} Icon={item.icon} />
|
||||||
className=""
|
|
||||||
variant="secondary"
|
|
||||||
key={item.id}
|
|
||||||
Icon={item.icon}
|
|
||||||
title={item.title}
|
|
||||||
url={item.url}
|
|
||||||
dev={item.dev}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
<GeneralSettings />
|
<GeneralSettings />
|
||||||
<AccountSettings />
|
<AccountSettings />
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
import { IconType } from "react-icons";
|
|
||||||
import { NavLink } from "react-router-dom";
|
import { NavLink } from "react-router-dom";
|
||||||
import { ENV } from "@/env";
|
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
@ -8,6 +6,8 @@ import {
|
|||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { isDesktop } from "react-device-detect";
|
import { isDesktop } from "react-device-detect";
|
||||||
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
||||||
|
import { NavData } from "@/types/navigation";
|
||||||
|
import { IconType } from "react-icons";
|
||||||
|
|
||||||
const variants = {
|
const variants = {
|
||||||
primary: {
|
primary: {
|
||||||
@ -21,37 +21,29 @@ const variants = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type NavItemProps = {
|
type NavItemProps = {
|
||||||
className: string;
|
className?: string;
|
||||||
variant?: "primary" | "secondary";
|
item: NavData;
|
||||||
Icon: IconType;
|
Icon: IconType;
|
||||||
title: string;
|
|
||||||
url: string;
|
|
||||||
dev?: boolean;
|
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NavItem({
|
export default function NavItem({
|
||||||
className,
|
className,
|
||||||
variant = "primary",
|
item,
|
||||||
Icon,
|
Icon,
|
||||||
title,
|
|
||||||
url,
|
|
||||||
dev,
|
|
||||||
onClick,
|
onClick,
|
||||||
}: NavItemProps) {
|
}: NavItemProps) {
|
||||||
const shouldRender = dev ? ENV !== "production" : true;
|
if (item.enabled == false) {
|
||||||
|
|
||||||
if (!shouldRender) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<NavLink
|
<NavLink
|
||||||
to={url}
|
to={item.url}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
`${className} flex flex-col justify-center items-center rounded-lg ${
|
`flex flex-col justify-center items-center rounded-lg ${className ?? ""} ${
|
||||||
variants[variant][isActive ? "active" : "inactive"]
|
variants[item.variant ?? "primary"][isActive ? "active" : "inactive"]
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@ -65,7 +57,7 @@ export default function NavItem({
|
|||||||
<TooltipTrigger>{content}</TooltipTrigger>
|
<TooltipTrigger>{content}</TooltipTrigger>
|
||||||
<TooltipPortal>
|
<TooltipPortal>
|
||||||
<TooltipContent side="right">
|
<TooltipContent side="right">
|
||||||
<p>{title}</p>
|
<p>{item.title}</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</TooltipPortal>
|
</TooltipPortal>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
import Logo from "../Logo";
|
import Logo from "../Logo";
|
||||||
import { navbarLinks } from "@/pages/site-navigation";
|
|
||||||
import NavItem from "./NavItem";
|
import NavItem from "./NavItem";
|
||||||
import { CameraGroupSelector } from "../filter/CameraGroupSelector";
|
import { CameraGroupSelector } from "../filter/CameraGroupSelector";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import GeneralSettings from "../settings/GeneralSettings";
|
import GeneralSettings from "../settings/GeneralSettings";
|
||||||
import AccountSettings from "../settings/AccountSettings";
|
import AccountSettings from "../settings/AccountSettings";
|
||||||
|
import useNavigation from "@/hooks/use-navigation";
|
||||||
|
|
||||||
function Sidebar() {
|
function Sidebar() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
const navbarLinks = useNavigation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="absolute w-[52px] z-10 left-o inset-y-0 overflow-y-auto scrollbar-hidden py-4 flex flex-col justify-between bg-background_alt border-r border-secondary-highlight">
|
<aside className="absolute w-[52px] z-10 left-o inset-y-0 overflow-y-auto scrollbar-hidden py-4 flex flex-col justify-between bg-background_alt border-r border-secondary-highlight">
|
||||||
<span tabIndex={0} className="sr-only" />
|
<span tabIndex={0} className="sr-only" />
|
||||||
@ -22,10 +24,8 @@ function Sidebar() {
|
|||||||
<div key={item.id}>
|
<div key={item.id}>
|
||||||
<NavItem
|
<NavItem
|
||||||
className={`mx-[10px] ${showCameraGroups ? "mb-2" : "mb-4"}`}
|
className={`mx-[10px] ${showCameraGroups ? "mb-2" : "mb-4"}`}
|
||||||
|
item={item}
|
||||||
Icon={item.icon}
|
Icon={item.icon}
|
||||||
title={item.title}
|
|
||||||
url={item.url}
|
|
||||||
dev={item.dev}
|
|
||||||
/>
|
/>
|
||||||
{showCameraGroups && <CameraGroupSelector className="mb-4" />}
|
{showCameraGroups && <CameraGroupSelector className="mb-4" />}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
59
web/src/hooks/use-navigation.ts
Normal file
59
web/src/hooks/use-navigation.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import Logo from "@/components/Logo";
|
||||||
|
import { ENV } from "@/env";
|
||||||
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
|
import { NavData } from "@/types/navigation";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import { FaCompactDisc, FaVideo } from "react-icons/fa";
|
||||||
|
import { LuConstruction } from "react-icons/lu";
|
||||||
|
import { MdVideoLibrary } from "react-icons/md";
|
||||||
|
import useSWR from "swr";
|
||||||
|
|
||||||
|
export default function useNavigation(
|
||||||
|
variant: "primary" | "secondary" = "primary",
|
||||||
|
) {
|
||||||
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
|
||||||
|
return useMemo(
|
||||||
|
() =>
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
variant,
|
||||||
|
icon: FaVideo,
|
||||||
|
title: "Live",
|
||||||
|
url: "/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
variant,
|
||||||
|
icon: MdVideoLibrary,
|
||||||
|
title: "Review",
|
||||||
|
url: "/review",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
variant,
|
||||||
|
icon: FaCompactDisc,
|
||||||
|
title: "Export",
|
||||||
|
url: "/export",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
variant,
|
||||||
|
icon: Logo,
|
||||||
|
title: "Frigate+",
|
||||||
|
url: "/plus",
|
||||||
|
enabled: config?.plus?.enabled == true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
variant,
|
||||||
|
icon: LuConstruction,
|
||||||
|
title: "UI Playground",
|
||||||
|
url: "/playground",
|
||||||
|
enabled: ENV !== "production",
|
||||||
|
},
|
||||||
|
] as NavData[],
|
||||||
|
[config?.plus.enabled, variant],
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,38 +0,0 @@
|
|||||||
import Logo from "@/components/Logo";
|
|
||||||
import { FaCompactDisc, FaVideo } from "react-icons/fa";
|
|
||||||
import { LuConstruction } from "react-icons/lu";
|
|
||||||
import { MdVideoLibrary } from "react-icons/md";
|
|
||||||
|
|
||||||
export const navbarLinks = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
icon: FaVideo,
|
|
||||||
title: "Live",
|
|
||||||
url: "/",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
icon: MdVideoLibrary,
|
|
||||||
title: "Review",
|
|
||||||
url: "/review",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
icon: FaCompactDisc,
|
|
||||||
title: "Export",
|
|
||||||
url: "/export",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
icon: Logo,
|
|
||||||
title: "Frigate+",
|
|
||||||
url: "/plus",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
icon: LuConstruction,
|
|
||||||
title: "UI Playground",
|
|
||||||
url: "/playground",
|
|
||||||
dev: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
10
web/src/types/navigation.ts
Normal file
10
web/src/types/navigation.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { IconType } from "react-icons";
|
||||||
|
|
||||||
|
export type NavData = {
|
||||||
|
id: number;
|
||||||
|
variant?: "primary" | "secondary";
|
||||||
|
icon: IconType;
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user