From 495ac1b36d2a1a6310db38eb2ce0480a9589ae51 Mon Sep 17 00:00:00 2001 From: Danny Avila <110412045+danny-avila@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:04:44 -0400 Subject: [PATCH] fix(Chat): correctly render when refreshing/visiting a conversation page (#1037) --- client/src/components/Nav/NewChat.tsx | 6 +++--- client/src/routes/Chat.tsx | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/src/components/Nav/NewChat.tsx b/client/src/components/Nav/NewChat.tsx index fa2a8aa184..a876f4a810 100644 --- a/client/src/components/Nav/NewChat.tsx +++ b/client/src/components/Nav/NewChat.tsx @@ -1,14 +1,14 @@ -import React from 'react'; +import { useNavigate } from 'react-router-dom'; import { useLocalize, useConversation } from '~/hooks'; export default function NewChat() { const { newConversation } = useConversation(); + const navigate = useNavigate(); const localize = useLocalize(); const clickHandler = () => { - // dispatch(setInputValue('')); - // dispatch(setQuery('')); newConversation(); + navigate('/chat/new'); }; return ( diff --git a/client/src/routes/Chat.tsx b/client/src/routes/Chat.tsx index eb39c987d9..d24ef3e085 100644 --- a/client/src/routes/Chat.tsx +++ b/client/src/routes/Chat.tsx @@ -27,7 +27,7 @@ export default function Chat() { const navigate = useNavigate(); //disabled by default, we only enable it when messagesTree is null - const messagesQuery = useGetMessagesByConvoId(conversationId ?? '', { enabled: false }); + const messagesQuery = useGetMessagesByConvoId(conversationId ?? '', { enabled: !messagesTree }); const getConversationMutation = useGetConversationByIdMutation(conversationId ?? ''); const { data: config } = useGetStartupConfig(); @@ -89,7 +89,8 @@ export default function Chat() { setShouldNavigate(false); } // conversationId (in url) should always follow conversation?.conversationId, unless conversation is null - else if (conversation?.conversationId !== conversationId) { + // messagesTree is null when user navigates, but not on page refresh, so we need to navigate in this case + else if (conversation?.conversationId !== conversationId && !messagesTree) { if (shouldNavigate) { navigate(`/chat/${conversation?.conversationId}`); } else {