'use client' import { useTranslation } from 'react-i18next' import { Fragment, useCallback } from 'react' import { RiAddLine, RiArrowDownSLine, RiArrowRightSLine, } from '@remixicon/react' import { Menu, Transition } from '@headlessui/react' import { useRouter } from 'next/navigation' import { debounce } from 'lodash-es' import cn from '@/utils/classnames' import AppIcon from '@/app/components/base/app-icon' import { AiText, ChatBot, CuteRobot } from '@/app/components/base/icons/src/vender/solid/communication' import { Route } from '@/app/components/base/icons/src/vender/solid/mapsAndTravel' import { useAppContext } from '@/context/app-context' import { useStore as useAppStore } from '@/app/components/app/store' import { FileArrow01, FilePlus01, FilePlus02 } from '@/app/components/base/icons/src/vender/line/files' import type { AppIconType } from '@/types/app' export type NavItem = { id: string name: string link: string icon_type: AppIconType | null icon: string icon_background: string icon_url: string | null mode?: string } export type INavSelectorProps = { navs: NavItem[] curNav?: Omit createText: string isApp?: boolean onCreate: (state: string) => void onLoadmore?: () => void } const NavSelector = ({ curNav, navs, createText, isApp, onCreate, onLoadmore }: INavSelectorProps) => { const { t } = useTranslation() const router = useRouter() const { isCurrentWorkspaceEditor } = useAppContext() const setAppDetail = useAppStore(state => state.setAppDetail) const handleScroll = useCallback(debounce((e) => { if (typeof onLoadmore === 'function') { const { clientHeight, scrollHeight, scrollTop } = e.target if (clientHeight + scrollTop > scrollHeight - 50) onLoadmore() } }, 50), []) return (
{({ open }) => ( <>
{curNav?.name}
{ navs.map(nav => (
{ if (curNav?.id === nav.id) return setAppDetail() router.push(nav.link) }} title={nav.name}>
{!!nav.mode && ( {nav.mode === 'advanced-chat' && ( )} {nav.mode === 'agent-chat' && ( )} {nav.mode === 'chat' && ( )} {nav.mode === 'completion' && ( )} {nav.mode === 'workflow' && ( )} )}
{nav.name}
)) }
{!isApp && isCurrentWorkspaceEditor && (
onCreate('')} className={cn( 'flex items-center gap-2 px-3 py-[6px] rounded-lg cursor-pointer hover:bg-gray-100', )}>
{createText}
)} {isApp && isCurrentWorkspaceEditor && ( {({ open }) => ( <>
{createText}
onCreate('blank')}> {t('app.newApp.startFromBlank')}
onCreate('template')}> {t('app.newApp.startFromTemplate')}
onCreate('dsl')}> {t('app.importDSL')}
)}
)}
)}
) } export default NavSelector