Skip to content
Snippets Groups Projects
nav-mobile.tsx 1.51 KiB
Newer Older
"use client"

import { Icons } from "@/components/icons"
import { SidebarNavItem } from "@/types"
import { User } from "next-auth"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { Button } from "./ui/button"

export const MobileNav = ({ items, user }: { items: SidebarNavItem[], user: User | undefined }) => {
    const path = usePathname()

    if (!items?.length) {
        return null
    }

    const visibleItems = user ? items : items.slice(0, 2)

    return (
Yusuf Akgül's avatar
Yusuf Akgül committed
        <nav className={`container flex flex-row items-center h-full w-full max-w-lg justify-between mx-auto`}>
            {visibleItems.map((item, index) => {
                const Icon = Icons[item.icon || "arrowRight"]
                if (item.title === "My Profile") {
                    item.href = `/${user?.username}`
                }
Yusuf Akgül's avatar
Yusuf Akgül committed
                if (item.title === "Settings") {
                    return
                }
Yusuf Akgül's avatar
Yusuf Akgül committed
                if (item.title === "Help / FAQ") {
Yusuf Akgül's avatar
Yusuf Akgül committed
                    return
                }
                return (
                    item.href && (
Yusuf Akgül's avatar
Yusuf Akgül committed
                        <Link key={index} href={item.disabled ? "/" : item.href} className="inline-flex items-center justify-center w-full h-full">
                            <Button variant={`${path.startsWith(item.href) ? "secondary" : "ghost"}`} size="logo">
                                <Icon />
                            </Button>
                        </Link>
                    )
                )
            })}
        </nav>
    )
}