import React, { useCallback } from 'react'; import { Link } 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 { CLOSE_SIDEBAR_ID, OPEN_SIDEBAR_ID } from '~/components/Chat/Menus/OpenSidebar'; 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 localize = useLocalize(); const { conversation } = store.useCreateConversationAtom(index); const handleToggleNav = useCallback(() => { toggleNav(); // Delay focus until after the sidebar animation completes (200ms) setTimeout(() => { document.getElementById(OPEN_SIDEBAR_ID)?.focus(); }, 250); }, [toggleNav]); const clickHandler: React.MouseEventHandler = useCallback( (e) => { // Let browser handle modified/non-left clicks (new tab, context menu, etc.) if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) { return; } e.preventDefault(); clearMessagesCache(queryClient, conversation?.conversationId); queryClient.invalidateQueries([QueryKeys.messages]); newConvo(); if (isSmallScreen) { toggleNav(); } }, [queryClient, conversation, newConvo, toggleNav, isSmallScreen], ); return ( <>
{subHeaders != null ? subHeaders : null} ); }