Skip to content

Commit

Permalink
fix(Chat): correctly render when refreshing/visiting a conversation page
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila committed Oct 10, 2023
1 parent b3aac97 commit 3921f5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions client/src/components/Nav/NewChat.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions client/src/routes/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3921f5e

Please sign in to comment.