From 2816caf0f28c47960f6bf774fa29be1ae04fabb6 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 14 May 2024 15:08:33 -0400 Subject: [PATCH] fix: correctly navigate to new conversation when deleting/archiving a new, active convo --- .../components/Conversations/ArchiveButton.tsx | 16 ++++++++-------- .../components/Conversations/DeleteButton.tsx | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/client/src/components/Conversations/ArchiveButton.tsx b/client/src/components/Conversations/ArchiveButton.tsx index ce53584af75..d35e61c9147 100644 --- a/client/src/components/Conversations/ArchiveButton.tsx +++ b/client/src/components/Conversations/ArchiveButton.tsx @@ -1,12 +1,10 @@ -import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '~/components/ui'; +import { useParams, useNavigate } from 'react-router-dom'; import type { MouseEvent, FocusEvent, KeyboardEvent } from 'react'; -import { useParams } from 'react-router-dom'; - -import { useArchiveConversationMutation } from '~/data-provider'; - +import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '~/components/ui'; import { useConversations, useLocalize, useNewConvo } from '~/hooks'; -import { useToastContext } from '~/Providers'; +import { useArchiveConversationMutation } from '~/data-provider'; import { NotificationSeverity } from '~/common'; +import { useToastContext } from '~/Providers'; type ArchiveButtonProps = { conversationId: string; @@ -23,8 +21,9 @@ export default function ArchiveButton({ className = '', }: ArchiveButtonProps) { const localize = useLocalize(); - const { newConversation } = useNewConvo(); + const navigate = useNavigate(); const { showToast } = useToastContext(); + const { newConversation } = useNewConvo(); const { refreshConversations } = useConversations(); const { conversationId: currentConvoId } = useParams(); @@ -42,8 +41,9 @@ export default function ArchiveButton({ { conversationId, isArchived: shouldArchive }, { onSuccess: () => { - if (currentConvoId === conversationId) { + if (currentConvoId === conversationId || currentConvoId === 'new') { newConversation(); + navigate('/c/new', { replace: true }); } refreshConversations(); retainView(); diff --git a/client/src/components/Conversations/DeleteButton.tsx b/client/src/components/Conversations/DeleteButton.tsx index 31aa337ec80..904846ab705 100644 --- a/client/src/components/Conversations/DeleteButton.tsx +++ b/client/src/components/Conversations/DeleteButton.tsx @@ -1,7 +1,7 @@ import { useCallback } from 'react'; -import { useParams } from 'react-router-dom'; import { QueryKeys } from 'librechat-data-provider'; import { useQueryClient } from '@tanstack/react-query'; +import { useParams, useNavigate } from 'react-router-dom'; import type { TMessage } from 'librechat-data-provider'; import { useDeleteConversationMutation } from '~/data-provider'; import { @@ -26,13 +26,15 @@ export default function DeleteButton({ className = '', }) { const localize = useLocalize(); + const navigate = useNavigate(); const queryClient = useQueryClient(); const { newConversation } = useNewConvo(); const { conversationId: currentConvoId } = useParams(); const deleteConvoMutation = useDeleteConversationMutation({ onSuccess: () => { - if (currentConvoId === conversationId) { + if (currentConvoId === conversationId || currentConvoId === 'new') { newConversation(); + navigate('/c/new', { replace: true }); } retainView(); },