'use client' import { useCallback } from 'react' import { ChevronDownIcon, PlusIcon } from '@heroicons/react/24/solid' import { Menu } from '@headlessui/react' import { useRouter } from 'next/navigation' import { debounce } from 'lodash-es' import Indicator from '../../indicator' import AppIcon from '@/app/components/base/app-icon' import { useAppContext } from '@/context/app-context' type NavItem = { id: string name: string link: string icon: string icon_background: string } export type INavSelectorProps = { navs: NavItem[] curNav?: Omit createText: string onCreate: () => void onLoadmore?: () => void } const itemClassName = ` flex items-center w-full h-10 px-3 text-gray-700 text-[14px] rounded-lg font-normal hover:bg-gray-100 cursor-pointer truncate ` const NavSelector = ({ curNav, navs, createText, onCreate, onLoadmore }: INavSelectorProps) => { const router = useRouter() const { isCurrentWorkspaceManager } = useAppContext() const handleScroll = useCallback(debounce((e) => { if (typeof onLoadmore === 'function') { const { clientHeight, scrollHeight, scrollTop } = e.target if (clientHeight + scrollTop > scrollHeight - 50) onLoadmore() } }, 50), []) return (
{curNav?.name}
{ navs.map(nav => (
router.push(nav.link)} title={nav.name}>
{nav.name}
)) }
{isCurrentWorkspaceManager &&
{createText}
}
) } export default NavSelector