From 7f31946ee45d8fc2ca57fa680a9a106e597ec923 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 6 Jan 2025 10:20:45 -0500 Subject: [PATCH] refactor: integrate queryClient to reset message data on new conversation initiation --- .../src/components/Chat/Menus/HeaderNewChat.tsx | 16 +++++++++++++--- client/src/components/Nav/MobileNav.tsx | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/client/src/components/Chat/Menus/HeaderNewChat.tsx b/client/src/components/Chat/Menus/HeaderNewChat.tsx index 200e73d17e4..3e29190e7cf 100644 --- a/client/src/components/Chat/Menus/HeaderNewChat.tsx +++ b/client/src/components/Chat/Menus/HeaderNewChat.tsx @@ -1,9 +1,13 @@ +import { useQueryClient } from '@tanstack/react-query'; +import { QueryKeys, Constants } from 'librechat-data-provider'; +import type { TMessage } from 'librechat-data-provider'; +import { useMediaQuery, useLocalize } from '~/hooks'; import { NewChatIcon } from '~/components/svg'; import { useChatContext } from '~/Providers'; -import { useMediaQuery, useLocalize } from '~/hooks'; export default function HeaderNewChat() { - const { newConversation } = useChatContext(); + const queryClient = useQueryClient(); + const { conversation, newConversation } = useChatContext(); const isSmallScreen = useMediaQuery('(max-width: 768px)'); const localize = useLocalize(); if (isSmallScreen) { @@ -15,7 +19,13 @@ export default function HeaderNewChat() { aria-label={localize('com_ui_new_chat')} type="button" className="btn btn-neutral btn-small border-token-border-medium focus:border-black-500 dark:focus:border-white-500 relative ml-2 flex h-9 w-9 items-center justify-center whitespace-nowrap rounded-lg border md:flex" - onClick={() => newConversation()} + onClick={() => { + queryClient.setQueryData( + [QueryKeys.messages, conversation?.conversationId ?? Constants.NEW_CONVO], + [], + ); + newConversation(); + }} >
diff --git a/client/src/components/Nav/MobileNav.tsx b/client/src/components/Nav/MobileNav.tsx index d325842487d..7cbef8c7dcf 100644 --- a/client/src/components/Nav/MobileNav.tsx +++ b/client/src/components/Nav/MobileNav.tsx @@ -1,5 +1,8 @@ import React from 'react'; import { useRecoilValue } from 'recoil'; +import { useQueryClient } from '@tanstack/react-query'; +import { QueryKeys, Constants } from 'librechat-data-provider'; +import type { TMessage } from 'librechat-data-provider'; import type { Dispatch, SetStateAction } from 'react'; import { useLocalize, useNewConvo } from '~/hooks'; import store from '~/store'; @@ -10,6 +13,7 @@ export default function MobileNav({ setNavVisible: Dispatch>; }) { const localize = useLocalize(); + const queryClient = useQueryClient(); const { newConversation } = useNewConvo(0); const conversation = useRecoilValue(store.conversationByIndex(0)); const { title = 'New Chat' } = conversation || {}; @@ -46,13 +50,19 @@ export default function MobileNav({

- {title || localize('com_ui_new_chat')} + {title ?? localize('com_ui_new_chat')}