Skip to content

Commit

Permalink
fix: change to new session after history deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Nov 29, 2023
1 parent 37eaa5c commit f4b7b2e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 14 additions & 4 deletions public/tabs/history/chat_history_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,7 +34,14 @@ interface ChatHistoryPageProps {
export const ChatHistoryPage: React.FC<ChatHistoryPageProps> = 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<string>();
Expand Down Expand Up @@ -70,11 +78,13 @@ export const ChatHistoryPage: React.FC<ChatHistoryPageProps> = 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(
Expand Down
8 changes: 4 additions & 4 deletions public/tabs/history/chat_history_search_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -61,7 +61,7 @@ export const ChatHistorySearchList = ({
[setEditingConversation, onRefresh]
);

const handleDeleteConversationCancel = useCallback(
const handleDeleteConversationConfirmModalClose = useCallback(
(status: 'deleted' | string) => {
if (status === 'deleted') {
onRefresh();
Expand Down Expand Up @@ -108,15 +108,15 @@ export const ChatHistorySearchList = ({
/>
{editingConversation && (
<EditConversationNameModal
onClose={handleEditConversationCancel}
onClose={handleEditConversationConfirmModalClose}
sessionId={editingConversation.id}
defaultTitle={editingConversation.title}
/>
)}
{deletingConversation && (
<DeleteConversationConfirmModal
sessionId={deletingConversation.id}
onClose={handleDeleteConversationCancel}
onClose={handleDeleteConversationConfirmModalClose}
/>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion public/tabs/history/delete_conversation_confirm_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f4b7b2e

Please sign in to comment.