import { Search } from 'lucide-react'; import { useRecoilValue } from 'recoil'; import { useNavigate } from 'react-router-dom'; import { useGetEndpointsQuery } from 'librechat-data-provider/react-query'; import type { TConversation } from 'librechat-data-provider'; import { getEndpointField, getIconEndpoint, getIconKey } from '~/utils'; import { icons } from '~/components/Chat/Menus/Endpoints/Icons'; import ConvoIconURL from '~/components/Endpoints/ConvoIconURL'; import { useLocalize, useNewConvo } from '~/hooks'; import { TooltipAnchor } from '~/components/ui'; import { NewChatIcon } from '~/components/svg'; import store from '~/store'; const NewChatButtonIcon = ({ conversation }: { conversation: TConversation | null }) => { const searchQuery = useRecoilValue(store.searchQuery); const { data: endpointsConfig } = useGetEndpointsQuery(); if (searchQuery) { return (
); } let { endpoint = '' } = conversation ?? {}; const iconURL = conversation?.iconURL ?? ''; endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint }); const endpointType = getEndpointField(endpointsConfig, endpoint, 'type'); const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL'); const iconKey = getIconKey({ endpoint, endpointsConfig, endpointType, endpointIconURL }); const Icon = icons[iconKey]; return (
{iconURL && iconURL.includes('http') ? ( ) : (
{endpoint && Icon != null && ( )}
)}
); }; export default function NewChat({ index = 0, toggleNav, subHeaders, }: { index?: number; toggleNav: () => void; subHeaders?: React.ReactNode; }) { /** Note: this component needs an explicit index passed if using more than one */ const { newConversation: newConvo } = useNewConvo(index); const navigate = useNavigate(); const localize = useLocalize(); const { conversation } = store.useCreateConversationAtom(index); const clickHandler = (event: React.MouseEvent) => { if (event.button === 0 && !(event.ctrlKey || event.metaKey)) { event.preventDefault(); newConvo(); navigate('/c/new'); toggleNav(); } }; return (
{localize('com_ui_new_chat')}
{subHeaders != null ? subHeaders : null}
); }