Skip to content

Commit

Permalink
fix: correctly navigate to new conversation when deleting/archiving a…
Browse files Browse the repository at this point in the history
… new, active convo
  • Loading branch information
danny-avila committed May 14, 2024
1 parent 2be84c4 commit 2816caf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions client/src/components/Conversations/ArchiveButton.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/Conversations/DeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
},
Expand Down

0 comments on commit 2816caf

Please sign in to comment.