From 360a6a68b45ffd05ace24bda8e93640d8f61ac1f Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 11 Apr 2024 10:20:58 -0600 Subject: [PATCH] Only show frigate+ page when frigate+ is enabled --- web/src/components/navigation/Bottombar.tsx | 16 ++---- web/src/components/navigation/NavItem.tsx | 28 ++++------ web/src/components/navigation/Sidebar.tsx | 8 +-- web/src/hooks/use-navigation.ts | 59 +++++++++++++++++++++ web/src/pages/site-navigation.ts | 38 ------------- web/src/types/navigation.ts | 10 ++++ 6 files changed, 88 insertions(+), 71 deletions(-) create mode 100644 web/src/hooks/use-navigation.ts delete mode 100644 web/src/pages/site-navigation.ts create mode 100644 web/src/types/navigation.ts diff --git a/web/src/components/navigation/Bottombar.tsx b/web/src/components/navigation/Bottombar.tsx index 6334b04b05..2ef8c2e8d4 100644 --- a/web/src/components/navigation/Bottombar.tsx +++ b/web/src/components/navigation/Bottombar.tsx @@ -1,4 +1,3 @@ -import { navbarLinks } from "@/pages/site-navigation"; import NavItem from "./NavItem"; import { IoIosWarning } from "react-icons/io"; import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer"; @@ -9,20 +8,15 @@ import { useMemo } from "react"; import useStats from "@/hooks/use-stats"; import GeneralSettings from "../settings/GeneralSettings"; import AccountSettings from "../settings/AccountSettings"; +import useNavigation from "@/hooks/use-navigation"; function Bottombar() { + const navItems = useNavigation("secondary"); + return (
- {navbarLinks.map((item) => ( - + {navItems.map((item) => ( + ))} diff --git a/web/src/components/navigation/NavItem.tsx b/web/src/components/navigation/NavItem.tsx index 1b42e5f7b4..6b8295be92 100644 --- a/web/src/components/navigation/NavItem.tsx +++ b/web/src/components/navigation/NavItem.tsx @@ -1,6 +1,4 @@ -import { IconType } from "react-icons"; import { NavLink } from "react-router-dom"; -import { ENV } from "@/env"; import { Tooltip, TooltipContent, @@ -8,6 +6,8 @@ import { } from "@/components/ui/tooltip"; import { isDesktop } from "react-device-detect"; import { TooltipPortal } from "@radix-ui/react-tooltip"; +import { NavData } from "@/types/navigation"; +import { IconType } from "react-icons"; const variants = { primary: { @@ -21,37 +21,29 @@ const variants = { }; type NavItemProps = { - className: string; - variant?: "primary" | "secondary"; + className?: string; + item: NavData; Icon: IconType; - title: string; - url: string; - dev?: boolean; onClick?: () => void; }; export default function NavItem({ className, - variant = "primary", + item, Icon, - title, - url, - dev, onClick, }: NavItemProps) { - const shouldRender = dev ? ENV !== "production" : true; - - if (!shouldRender) { + if (item.enabled == false) { return; } const content = ( - `${className} flex flex-col justify-center items-center rounded-lg ${ - variants[variant][isActive ? "active" : "inactive"] + `flex flex-col justify-center items-center rounded-lg ${className ?? ""} ${ + variants[item.variant ?? "primary"][isActive ? "active" : "inactive"] }` } > @@ -65,7 +57,7 @@ export default function NavItem({ {content} -

{title}

+

{item.title}

diff --git a/web/src/components/navigation/Sidebar.tsx b/web/src/components/navigation/Sidebar.tsx index d3cda81539..505ebe047d 100644 --- a/web/src/components/navigation/Sidebar.tsx +++ b/web/src/components/navigation/Sidebar.tsx @@ -1,14 +1,16 @@ import Logo from "../Logo"; -import { navbarLinks } from "@/pages/site-navigation"; import NavItem from "./NavItem"; import { CameraGroupSelector } from "../filter/CameraGroupSelector"; import { useLocation } from "react-router-dom"; import GeneralSettings from "../settings/GeneralSettings"; import AccountSettings from "../settings/AccountSettings"; +import useNavigation from "@/hooks/use-navigation"; function Sidebar() { const location = useLocation(); + const navbarLinks = useNavigation(); + return (