🗨️ fix: Prevent Resetting Title to 'New Chat' on Follow-Up Message (#1870)

* fix: prevent reseting title to 'New Chat' on follow up message

* chore(useSSE): remove empty line
This commit is contained in:
Danny Avila 2024-02-23 10:20:46 -05:00 committed by GitHub
parent ece5d9f588
commit 6a25dd38a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 4 deletions

View file

@ -24,7 +24,12 @@ import type {
TSubmission,
ConversationData,
} from 'librechat-data-provider';
import { addConversation, deleteConversation, updateConversation } from '~/utils';
import {
addConversation,
deleteConversation,
updateConversation,
getConversationById,
} from '~/utils';
import { useGenTitleMutation } from '~/data-provider';
import useContentHandler from './useContentHandler';
import { useAuthContext } from '../AuthContext';
@ -231,13 +236,21 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
]);
}
const { conversationId } = message;
const { conversationId, parentMessageId } = message;
let update = {} as TConversation;
setConversation((prevState) => {
let title = prevState?.title;
if (parentMessageId !== Constants.NO_PARENT && title?.toLowerCase()?.includes('new chat')) {
const convos = queryClient.getQueryData<ConversationData>([QueryKeys.allConversations]);
const cachedConvo = getConversationById(convos, conversationId);
title = cachedConvo?.title;
}
update = tConvoUpdateSchema.parse({
...prevState,
conversationId,
title,
}) as TConversation;
setStorage(update);
@ -248,7 +261,7 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
if (!convoData) {
return convoData;
}
if (message.parentMessageId === Constants.NO_PARENT) {
if (parentMessageId === Constants.NO_PARENT) {
return addConversation(convoData, update);
} else {
return updateConversation(convoData, update);