From fc30482f6543fffcf3a04067ef18233f256f58cf Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Sun, 27 Apr 2025 18:28:28 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B6=20refactor:=20Chat=20Input=20Focus?= =?UTF-8?q?=20for=20Conversation=20Navigations=20&=20ChatForm=20Optimizati?= =?UTF-8?q?ons=20(#7100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: improve ChatView layout by keeping ChatForm mounted * feat: implement focusChat functionality for new conversations and navigations * refactor: reset artifacts when navigating to prevent any from rendering in a conversation when none exist; edge case, artifacts get created by search route (TODO: use a different artifact renderer for Search markdown) --- client/src/components/Chat/ChatView.tsx | 44 ++++++++++--------- client/src/components/Chat/Input/ChatForm.tsx | 3 +- client/src/components/Nav/NewChat.tsx | 2 +- client/src/hooks/Chat/index.ts | 1 + client/src/hooks/Chat/useChatFunctions.ts | 2 +- client/src/hooks/Chat/useFocusChatEffect.ts | 18 ++++++++ .../Conversations/useNavigateToConvo.tsx | 10 +++-- client/src/hooks/useNewConvo.ts | 29 ++++++------ 8 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 client/src/hooks/Chat/useFocusChatEffect.ts diff --git a/client/src/components/Chat/ChatView.tsx b/client/src/components/Chat/ChatView.tsx index 9196b3f23c..a180bb92ee 100644 --- a/client/src/components/Chat/ChatView.tsx +++ b/client/src/components/Chat/ChatView.tsx @@ -2,6 +2,7 @@ import { memo, useCallback } from 'react'; import { useRecoilValue } from 'recoil'; import { useForm } from 'react-hook-form'; import { useParams } from 'react-router-dom'; +import { Constants } from 'librechat-data-provider'; import { useGetMessagesByConvoId } from 'librechat-data-provider/react-query'; import type { TMessage } from 'librechat-data-provider'; import type { ChatFormValues } from '~/common'; @@ -11,8 +12,8 @@ import ConversationStarters from './Input/ConversationStarters'; import MessagesView from './Messages/MessagesView'; import { Spinner } from '~/components/svg'; import Presentation from './Presentation'; +import { buildTree, cn } from '~/utils'; import ChatForm from './Input/ChatForm'; -import { buildTree } from '~/utils'; import Landing from './Landing'; import Header from './Header'; import Footer from './Footer'; @@ -48,9 +49,11 @@ function ChatView({ index = 0 }: { index?: number }) { }); let content: JSX.Element | null | undefined; - const isLandingPage = !messagesTree || messagesTree.length === 0; + const isLandingPage = + (!messagesTree || messagesTree.length === 0) && + (conversationId === Constants.NEW_CONVO || !conversationId); - if (isLoading && conversationId !== 'new') { + if (isLoading && conversationId !== Constants.NEW_CONVO) { content = (
@@ -71,27 +74,28 @@ function ChatView({ index = 0 }: { index?: number }) {
{!isLoading &&
} - - {isLandingPage ? ( - <> -
- {content} -
- - -
-
-