diff --git a/public/tabs/history/chat_history_page.tsx b/public/tabs/history/chat_history_page.tsx index 3dc8fefd..004c9543 100644 --- a/public/tabs/history/chat_history_page.tsx +++ b/public/tabs/history/chat_history_page.tsx @@ -21,6 +21,7 @@ import { FormattedMessage } from '@osd/i18n/react'; import { useDebounce, useObservable } from 'react-use'; import cs from 'classnames'; import { useChatActions } from '../../hooks/use_chat_actions'; +import { useChatState } from '../../hooks/use_chat_state'; import { useChatContext } from '../../contexts/chat_context'; import { useCore } from '../../contexts/core_context'; import { ChatHistorySearchList } from './chat_history_search_list'; @@ -33,7 +34,14 @@ interface ChatHistoryPageProps { export const ChatHistoryPage: React.FC = React.memo((props) => { const { services } = useCore(); const { loadChat } = useChatActions(); - const { setSelectedTabId, flyoutFullScreen, sessionId } = useChatContext(); + const { chatStateDispatch } = useChatState(); + const { + setSelectedTabId, + flyoutFullScreen, + sessionId, + setSessionId, + setTitle, + } = useChatContext(); const [pageIndex, setPageIndex] = useState(0); const [pageSize, setPageSize] = useState(10); const [searchName, setSearchName] = useState(); @@ -70,11 +78,13 @@ export const ChatHistoryPage: React.FC = React.memo((props const handleHistoryDeleted = useCallback( (id: string) => { if (sessionId === id) { - // Switch to new conversation when current session be deleted - loadChat(); + // Clear old session chat states + setTitle(undefined); + setSessionId(undefined); + chatStateDispatch({ type: 'reset' }); } }, - [sessionId, loadChat] + [sessionId, setSessionId, setTitle, chatStateDispatch] ); useDebounce( diff --git a/public/tabs/history/chat_history_search_list.tsx b/public/tabs/history/chat_history_search_list.tsx index a14c7983..3f64cf70 100644 --- a/public/tabs/history/chat_history_search_list.tsx +++ b/public/tabs/history/chat_history_search_list.tsx @@ -51,7 +51,7 @@ export const ChatHistorySearchList = ({ } | null>(null); const [deletingConversation, setDeletingConversation] = useState<{ id: string } | null>(null); - const handleEditConversationCancel = useCallback( + const handleEditConversationConfirmModalClose = useCallback( (status: 'updated' | string) => { if (status === 'updated') { onRefresh(); @@ -61,7 +61,7 @@ export const ChatHistorySearchList = ({ [setEditingConversation, onRefresh] ); - const handleDeleteConversationCancel = useCallback( + const handleDeleteConversationConfirmModalClose = useCallback( (status: 'deleted' | string) => { if (status === 'deleted') { onRefresh(); @@ -108,7 +108,7 @@ export const ChatHistorySearchList = ({ /> {editingConversation && ( @@ -116,7 +116,7 @@ export const ChatHistorySearchList = ({ {deletingConversation && ( )} diff --git a/public/tabs/history/delete_conversation_confirm_modal.tsx b/public/tabs/history/delete_conversation_confirm_modal.tsx index adddd957..4da5c359 100644 --- a/public/tabs/history/delete_conversation_confirm_modal.tsx +++ b/public/tabs/history/delete_conversation_confirm_modal.tsx @@ -18,7 +18,7 @@ export const DeleteConversationConfirmModal = ({ onClose, sessionId, }: DeleteConversationConfirmModalProps) => { - const { loading, data, deleteSession, abortController } = useDeleteSession(); + const { loading, deleteSession, abortController } = useDeleteSession(); const handleCancel = useCallback(() => { abortController?.abort();