2023-05-14 21:12:17 +05:30
|
|
|
import { Menu, Transition } from '@headlessui/react';
|
2023-05-19 16:02:41 -04:00
|
|
|
import { Fragment, useState } from 'react';
|
|
|
|
|
import { useRecoilValue } from 'recoil';
|
2023-03-18 01:40:49 -04:00
|
|
|
import SearchBar from './SearchBar';
|
2023-05-19 16:02:41 -04:00
|
|
|
import TrashIcon from '../svg/TrashIcon';
|
|
|
|
|
import { Download } from 'lucide-react';
|
|
|
|
|
import NavLink from './NavLink';
|
|
|
|
|
import ExportModel from './ExportConversation/ExportModel';
|
2023-02-08 09:15:47 -05:00
|
|
|
import ClearConvos from './ClearConvos';
|
|
|
|
|
import DarkMode from './DarkMode';
|
2023-03-14 01:24:43 +08:00
|
|
|
import Logout from './Logout';
|
2023-05-14 21:12:17 +05:30
|
|
|
import { useAuthContext } from '~/hooks/AuthContext';
|
|
|
|
|
import { cn } from '~/utils/';
|
|
|
|
|
import DotsIcon from '../svg/DotsIcon';
|
2023-02-06 13:27:28 -05:00
|
|
|
|
2023-05-19 16:02:41 -04:00
|
|
|
import store from '~/store';
|
|
|
|
|
|
2023-04-06 05:47:37 -07:00
|
|
|
export default function NavLinks({ clearSearch, isSearchEnabled }) {
|
2023-05-19 16:02:41 -04:00
|
|
|
const [showExports, setShowExports] = useState(false);
|
|
|
|
|
const [showClearConvos, setShowClearConvos] = useState(false);
|
|
|
|
|
const { user } = useAuthContext();
|
|
|
|
|
|
|
|
|
|
const conversation = useRecoilValue(store.conversation) || {};
|
2023-05-14 21:12:17 +05:30
|
|
|
|
2023-05-19 16:02:41 -04:00
|
|
|
const exportable =
|
|
|
|
|
conversation?.conversationId &&
|
|
|
|
|
conversation?.conversationId !== 'new' &&
|
|
|
|
|
conversation?.conversationId !== 'search';
|
2023-05-14 21:12:17 +05:30
|
|
|
|
2023-05-19 16:02:41 -04:00
|
|
|
const clickHandler = () => {
|
|
|
|
|
if (exportable) setShowExports(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Menu as="div" className="group relative">
|
|
|
|
|
{({ open }) => (
|
|
|
|
|
<>
|
|
|
|
|
<Menu.Button
|
|
|
|
|
className={cn(
|
|
|
|
|
'group-ui-open:bg-gray-800 flex w-full items-center gap-2.5 rounded-md px-3 py-3 text-sm transition-colors duration-200 hover:bg-gray-800',
|
|
|
|
|
open ? 'bg-gray-800' : ''
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<div className="-ml-0.5 h-5 w-5 flex-shrink-0">
|
|
|
|
|
<div className="relative flex">
|
|
|
|
|
<img
|
|
|
|
|
className="rounded-sm"
|
|
|
|
|
src={
|
|
|
|
|
user?.avatar || `https://avatars.dicebear.com/api/initials/${user?.name}.svg`
|
|
|
|
|
}
|
|
|
|
|
alt=""
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grow overflow-hidden text-ellipsis whitespace-nowrap text-left text-white">
|
|
|
|
|
{user?.name || 'USER'}
|
|
|
|
|
</div>
|
|
|
|
|
<DotsIcon />
|
|
|
|
|
</Menu.Button>
|
2023-05-14 21:12:17 +05:30
|
|
|
|
2023-05-19 16:02:41 -04:00
|
|
|
<Transition
|
|
|
|
|
as={Fragment}
|
|
|
|
|
enter="transition ease-out duration-100"
|
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
|
leaveTo="transform opacity-0 scale-95"
|
|
|
|
|
>
|
|
|
|
|
<Menu.Items className="absolute bottom-full left-0 z-20 mb-2 w-full translate-y-0 overflow-hidden rounded-md bg-[#050509] py-1.5 opacity-100 outline-none">
|
|
|
|
|
<Menu.Item>
|
|
|
|
|
{!!isSearchEnabled && <SearchBar clearSearch={clearSearch} />}
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
<Menu.Item>
|
|
|
|
|
<NavLink
|
|
|
|
|
className={cn(
|
|
|
|
|
'flex w-full cursor-pointer items-center gap-3 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700',
|
|
|
|
|
exportable ? 'cursor-pointer text-white' : 'cursor-not-allowed text-gray-400'
|
|
|
|
|
)}
|
|
|
|
|
svg={() => <Download size={16} />}
|
|
|
|
|
text="Export conversation"
|
|
|
|
|
clickHandler={clickHandler}
|
|
|
|
|
/>
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
<div className="my-1.5 h-px bg-white/20" role="none" />
|
|
|
|
|
<Menu.Item>
|
|
|
|
|
<DarkMode />
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
<Menu.Item>
|
|
|
|
|
<NavLink
|
|
|
|
|
className="flex w-full cursor-pointer items-center gap-3 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700"
|
|
|
|
|
svg={() => <TrashIcon />}
|
|
|
|
|
text="Clear conversations"
|
|
|
|
|
clickHandler={() => setShowClearConvos(true)}
|
|
|
|
|
/>
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
<div className="my-1.5 h-px bg-white/20" role="none" />
|
|
|
|
|
<Menu.Item>
|
|
|
|
|
<Logout />
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
</Menu.Items>
|
|
|
|
|
</Transition>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Menu>
|
|
|
|
|
{showExports && <ExportModel open={showExports} onOpenChange={setShowExports} />}
|
|
|
|
|
{showClearConvos && <ClearConvos open={showClearConvos} onOpenChange={setShowClearConvos} />}
|
|
|
|
|
</>
|
2023-02-06 13:27:28 -05:00
|
|
|
);
|
|
|
|
|
}
|