Skip to content

Commit

Permalink
Merge pull request #312 from RamiAwar/dont-overwrite-named-chat
Browse files Browse the repository at this point in the history
Prevent overwriting user-named chat on first message
  • Loading branch information
RamiAwar authored Sep 1, 2024
2 parents e29ade0 + fda723c commit 03e6310
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions frontend/src/components/Conversation/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const Conversation = () => {
} = useQuery(
getMessagesQuery({ conversationId: params.conversationId ?? "" })
);
const currConversation = conversationsData?.find(
(conv) => conv.id === params.conversationId
);
const { mutate: generateConversationTitle } = useGenerateConversationTitle();
const {
mutate: sendMessageMutation,
Expand All @@ -62,7 +65,13 @@ export const Conversation = () => {
]),
onSettled: (_, error) => {
setStreamedResults([]);
if (!error && messages && messages.length < 2) {
if (
!error &&
messages &&
messages.length < 2 &&
currConversation?.name === "Untitled chat"
) {
// Generate a title for the conversation if it's untitled
generateConversationTitle({ id: params.conversationId ?? "" });
}
},
Expand All @@ -71,10 +80,6 @@ export const Conversation = () => {
const messageListRef = useRef<HTMLDivElement | null>(null);
const expandingInputRef = useRef<HTMLTextAreaElement | null>(null);

const currConversation = conversationsData?.find(
(conv) => conv.id === params.conversationId
);

const currConnection = connectionsData?.connections?.find(
(conn) => conn.id === currConversation?.connection_id
);
Expand Down

0 comments on commit 03e6310

Please sign in to comment.