diff --git a/src/components/SidebarItem.tsx b/src/components/SidebarItem.tsx index 7656436f..c4eb21ac 100644 --- a/src/components/SidebarItem.tsx +++ b/src/components/SidebarItem.tsx @@ -2,9 +2,9 @@ import * as Collapsible from "@radix-ui/react-collapsible"; import { cn } from "@utils/helpers"; -import classNames from "classnames"; import { ChevronDownIcon, ChevronUpIcon, DotIcon } from "lucide-react"; -import { usePathname, useRouter } from "next/navigation"; +import { usePathname } from "next/navigation"; +import Link from "next/link"; import React, { useEffect, useMemo } from "react"; import { useApplicationContext } from "@/contexts/ApplicationProvider"; @@ -52,106 +52,131 @@ export default function SidebarItem({ setOpen(true); } }, [hasActiveChild]); - const router = useRouter(); const { mobileNavOpen, toggleMobileNav, isNavigationCollapsed } = useApplicationContext(); - const handleClick = () => { - const preventRedirect = href + const isActive = useMemo(() => { + if (collapsible) return false; + return href ? exactPathMatch - ? path == href + ? path === href : path.includes(href) : false; - if (collapsible && href) return; - if (collapsible && mobileNavOpen) return; - if (collapsible && open) return; - if (preventRedirect) return; - if (target == "_blank") return window.open(href, "_blank"); + }, [path, href, exactPathMatch, collapsible]); + + const handleClick = (e: React.MouseEvent) => { + if (collapsible) return; + + if (isActive) { + return e.preventDefault(); + } + + if (target === "_blank") return; + if (mobileNavOpen) toggleMobileNav(); - router.push(href); }; - const isActive = useMemo(() => { - if (collapsible) return false; - return href ? (exactPathMatch ? path == href : path.includes(href)) : false; - }, [path, href, exactPathMatch, collapsible]); - if (!visible) return; - return ( - - -
  • - -
  • -
    - {collapsible && {children}} -
    + /> + ))} + + ); + + const itemContent = ( +
  • + {href && !collapsible ? ( + + {content} + + ) : ( + + )} +
  • + ); + + if (collapsible) { + return ( + + {itemContent} + {children} + + ); + } + + return itemContent; }