import React, { useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { QueryKeys } from 'librechat-data-provider'; import { useQueryClient } from '@tanstack/react-query'; import { TooltipAnchor, NewChatIcon, MobileSidebar, Sidebar, Button } from '@librechat/client'; import { useLocalize, useNewConvo } from '~/hooks'; import { clearMessagesCache } from '~/utils'; import store from '~/store'; export default function NewChat({ index = 0, toggleNav, subHeaders, isSmallScreen, headerButtons, }: { index?: number; toggleNav: () => void; isSmallScreen?: boolean; subHeaders?: React.ReactNode; headerButtons?: React.ReactNode; }) { const queryClient = useQueryClient(); /** 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: React.MouseEventHandler = useCallback( (e) => { if (e.button === 0 && (e.ctrlKey || e.metaKey)) { window.open('/c/new', '_blank'); return; } clearMessagesCache(queryClient, conversation?.conversationId); queryClient.invalidateQueries([QueryKeys.messages]); newConvo(); navigate('/c/new', { state: { focusChat: true } }); if (isSmallScreen) { toggleNav(); } }, [queryClient, conversation, newConvo, navigate, toggleNav, isSmallScreen], ); return ( <>
{subHeaders != null ? subHeaders : null} ); }