diff --git a/app/(admin)/layout.tsx b/app/(admin)/layout.tsx index ae71eb0..933b281 100644 --- a/app/(admin)/layout.tsx +++ b/app/(admin)/layout.tsx @@ -1,13 +1,13 @@ 'use client'; import { cn } from '@/lib/utils'; -import useStore from '@/hooks/use-store'; +import { useStore } from '@/hooks/use-store'; import { EdgeStoreProvider } from '@/lib/edgestore'; -import Footer from '@/components/admin-panel/footer'; +import { Footer } from '@/components/admin-panel/footer'; import Navbar from '@/components/admin-panel/navbar'; import Sidebar from '@/components/admin-panel/sidebar'; import ModalProvider from '@/providers/modal-provider'; -import useSidebarToggle from '@/hooks/use-sidebar-toggle'; +import { useSidebarToggle } from '@/hooks/use-sidebar-toggle'; export default function AdminLayout({ children diff --git a/app/auth/layout.tsx b/app/auth/layout.tsx index c803435..31cca59 100644 --- a/app/auth/layout.tsx +++ b/app/auth/layout.tsx @@ -1,5 +1,5 @@ -import ViewWebsite from '@/components/view-website'; import { ModeToggle } from '@/components/mode-toggle'; +import { ViewWebsite } from '@/components/view-website'; export default async function AuthLayout({ children diff --git a/components/admin-panel/collapse-menu-button.tsx b/components/admin-panel/collapse-menu-button.tsx new file mode 100644 index 0000000..3ac80bc --- /dev/null +++ b/components/admin-panel/collapse-menu-button.tsx @@ -0,0 +1,181 @@ +'use client'; + +import Link from 'next/link'; +import { useState } from 'react'; +import { ChevronDown, Dot, LucideIcon } from 'lucide-react'; + +import { cn } from '@/lib/utils'; +import { Button } from '@/components/ui/button'; +import { DropdownMenuArrow } from '@radix-ui/react-dropdown-menu'; +import { + Collapsible, + CollapsibleContent, + CollapsibleTrigger +} from '@/components/ui/collapsible'; +import { + Tooltip, + TooltipTrigger, + TooltipContent, + TooltipProvider +} from '@/components/ui/tooltip'; +import { + DropdownMenu, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuTrigger, + DropdownMenuContent, + DropdownMenuSeparator +} from '@/components/ui/dropdown-menu'; + +type Submenu = { + href: string; + label: string; + active: boolean; + onlyTitle?: boolean; +}; + +interface CollapseMenuButtonProps { + icon: LucideIcon; + label: string; + active: boolean; + submenus: Submenu[]; + isOpen: boolean | undefined; +} + +export function CollapseMenuButton({ + icon: Icon, + label, + active, + submenus, + isOpen +}: CollapseMenuButtonProps) { + const isSubmenuActive = submenus.some((submenu) => submenu.active); + const [isCollapsed, setIsCollapsed] = useState(isSubmenuActive); + + return isOpen ? ( + + + + + + {submenus + .filter((submenu) => !submenu.onlyTitle) + .map(({ href, label, active }, index) => ( + + ))} + + + ) : ( + + + + + + + + + + {label} + + + + + + {label} + + + {submenus + .filter((submenu) => !submenu.onlyTitle) + .map(({ href, label }, index) => ( + + +

{label}

+ +
+ ))} + +
+
+ ); +} diff --git a/components/admin-panel/footer.tsx b/components/admin-panel/footer.tsx index 2ae30a3..7cd7484 100644 --- a/components/admin-panel/footer.tsx +++ b/components/admin-panel/footer.tsx @@ -1,4 +1,4 @@ -export default function Footer() { +export function Footer() { return (
diff --git a/components/admin-panel/menu.tsx b/components/admin-panel/menu.tsx index 98cd211..cfe15bd 100644 --- a/components/admin-panel/menu.tsx +++ b/components/admin-panel/menu.tsx @@ -1,24 +1,14 @@ 'use client'; import Link from 'next/link'; -import { signOut } from 'next-auth/react'; import { usePathname } from 'next/navigation'; -import { - Book, - User, - List, - Text, - LogOut, - FileText, - FolderGit2, - LayoutGrid, - GraduationCap, - ClipboardCheck, - TerminalSquare -} from 'lucide-react'; +import { Ellipsis, LogOut } from 'lucide-react'; import { cn } from '@/lib/utils'; +import { getPages } from '@/lib/pages'; import { Button } from '@/components/ui/button'; +import { ScrollArea } from '@/components/ui/scroll-area'; +import { CollapseMenuButton } from '@/components/admin-panel/collapse-menu-button'; import { Tooltip, TooltipTrigger, @@ -30,140 +20,119 @@ interface MenuProps { isOpen: boolean | undefined; } -export default function Menu({ isOpen }: MenuProps) { +export function Menu({ isOpen }: MenuProps) { const pathname = usePathname(); - - const routes = [ - { - href: '/dashboard', - label: 'Dashboard', - active: pathname.includes('/dashboard'), - icon: - }, - { - href: '/about', - label: 'About', - active: pathname.includes('/about'), - icon: - }, - { - href: '/experience', - label: 'Experience', - active: pathname.includes('/experience'), - icon: - }, - { - href: '/expertise', - label: 'Expertise', - active: pathname.includes('/expertise'), - icon: - }, - { - href: '/qualification', - label: 'Qualification', - active: pathname.includes('/qualification'), - icon: - }, - { - href: '/portfolio', - label: 'Portfolio', - active: pathname.includes('/portfolio'), - icon: - }, - { - href: '/miscellaneous', - label: 'Miscellaneous', - active: pathname.includes('/miscellaneous'), - icon: - }, - { - href: '/tool', - label: 'Tool & Apps', - active: pathname.includes('/tool'), - icon: - }, - { - href: '/resume', - label: 'Resume', - active: pathname.includes('/resume'), - icon: - }, - { - href: '/account', - label: 'Account', - active: pathname.includes('/account'), - icon: - } - ]; + const pages = getPages(pathname); return ( - + ); } diff --git a/components/admin-panel/navbar.tsx b/components/admin-panel/navbar.tsx index 742bde4..fb6bcf8 100644 --- a/components/admin-panel/navbar.tsx +++ b/components/admin-panel/navbar.tsx @@ -1,8 +1,8 @@ -import ViewWebsite from '@/components/view-website'; import { ModeToggle } from '@/components/mode-toggle'; -import UserNav from '@/components/admin-panel/user-nav'; -import PageTitle from '@/components/admin-panel/page-title'; -import SheetMenu from '@/components/admin-panel/sheet-menu'; +import { ViewWebsite } from '@/components/view-website'; +import { UserNav } from '@/components/admin-panel/user-nav'; +import { PageTitle } from '@/components/admin-panel/page-title'; +import { SheetMenu } from '@/components/admin-panel/sheet-menu'; export default function Navbar() { return ( diff --git a/components/admin-panel/page-title.tsx b/components/admin-panel/page-title.tsx index 22fcdf8..448d62f 100644 --- a/components/admin-panel/page-title.tsx +++ b/components/admin-panel/page-title.tsx @@ -1,33 +1,18 @@ 'use client'; +import { getPages } from '@/lib/pages'; import { usePathname } from 'next/navigation'; -export default function PageTitle() { +export function PageTitle() { const pathname = usePathname(); + const pages = getPages(pathname); - let pageTitle = ''; - - if (pathname === '/dashboard') { - pageTitle = 'Dashboard'; - } else if (pathname.includes('/about')) { - pageTitle = 'About'; - } else if (pathname.includes('/experience')) { - pageTitle = 'Experience'; - } else if (pathname.includes('/expertise')) { - pageTitle = 'Expertise'; - } else if (pathname.includes('/qualification')) { - pageTitle = 'Qualification'; - } else if (pathname.includes('/portfolio')) { - pageTitle = 'Portfolio'; - } else if (pathname.includes('/miscellaneous')) { - pageTitle = 'Miscellaneous'; - } else if (pathname.includes('/tool')) { - pageTitle = 'Tool & Apps'; - } else if (pathname.includes('/resume')) { - pageTitle = 'Resume'; - } else if (pathname.includes('/account')) { - pageTitle = 'Account'; - } + const pageTitle = pages.map(({ menus }) => { + const activeMenu = menus.find((menu) => menu.active); + return activeMenu?.submenus && activeMenu.submenus.length > 0 + ? activeMenu.submenus.find((submenu) => submenu.active)?.label + : activeMenu?.label ?? ''; + }); return

{pageTitle}

; } diff --git a/components/admin-panel/sheet-menu.tsx b/components/admin-panel/sheet-menu.tsx index 6e89bf4..deb6561 100644 --- a/components/admin-panel/sheet-menu.tsx +++ b/components/admin-panel/sheet-menu.tsx @@ -2,7 +2,7 @@ import Link from 'next/link'; import { LayoutTemplate, MenuIcon } from 'lucide-react'; import { Button } from '@/components/ui/button'; -import Menu from '@/components/admin-panel/menu'; +import { Menu } from '@/components/admin-panel/menu'; import { Sheet, SheetHeader, @@ -10,7 +10,7 @@ import { SheetContent } from '@/components/ui/sheet'; -export default function SheetMenu() { +export function SheetMenu() { return ( diff --git a/components/admin-panel/sidebar-toggle.tsx b/components/admin-panel/sidebar-toggle.tsx index 766e343..8bb41fd 100644 --- a/components/admin-panel/sidebar-toggle.tsx +++ b/components/admin-panel/sidebar-toggle.tsx @@ -8,10 +8,7 @@ interface SidebarToggleProps { setIsOpen?: () => void; } -export default function SidebarToggle({ - isOpen, - setIsOpen -}: SidebarToggleProps) { +export function SidebarToggle({ isOpen, setIsOpen }: SidebarToggleProps) { return (