mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-30 23:28:52 +01:00
* chore: typing * chore: typing * fix: enhance message scrolling logic to handle empty messages tree and ref checks * fix: optimize message selection logic with useCallback for better performance * chore: typing * refactor: optimize icon rendering * refactor: further optimize chat props * fix: remove unnecessary console log in useQueryParams cleanup * refactor: add queryClient to reset message data on new conversation initiation * refactor: update data-testid attributes for consistency and improve code readability * refactor: integrate queryClient to reset message data on new conversation initiation
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query';
|
|
import { QueryKeys, Constants } from 'librechat-data-provider';
|
|
import type { TMessage } from 'librechat-data-provider';
|
|
import { useMediaQuery, useLocalize } from '~/hooks';
|
|
import { NewChatIcon } from '~/components/svg';
|
|
import { useChatContext } from '~/Providers';
|
|
|
|
export default function HeaderNewChat() {
|
|
const queryClient = useQueryClient();
|
|
const { conversation, newConversation } = useChatContext();
|
|
const isSmallScreen = useMediaQuery('(max-width: 768px)');
|
|
const localize = useLocalize();
|
|
if (isSmallScreen) {
|
|
return null;
|
|
}
|
|
return (
|
|
<button
|
|
data-testid="wide-header-new-chat-button"
|
|
aria-label={localize('com_ui_new_chat')}
|
|
type="button"
|
|
className="btn btn-neutral btn-small border-token-border-medium focus:border-black-500 dark:focus:border-white-500 relative ml-2 flex h-9 w-9 items-center justify-center whitespace-nowrap rounded-lg border md:flex"
|
|
onClick={() => {
|
|
queryClient.setQueryData<TMessage[]>(
|
|
[QueryKeys.messages, conversation?.conversationId ?? Constants.NEW_CONVO],
|
|
[],
|
|
);
|
|
newConversation();
|
|
}}
|
|
>
|
|
<div className="flex w-full items-center justify-center gap-2">
|
|
<NewChatIcon />
|
|
</div>
|
|
</button>
|
|
);
|
|
}
|