*️⃣ refactor(DeleteButton): Conversation List Behavior after Deletion (#2414)

* Refactor DeleteButton component in client/src/components/Conversations/DeleteButton.tsx

* chore: bump data-provider package

* chore: remove console.log
This commit is contained in:
Danny Avila 2024-04-14 19:11:55 -04:00 committed by GitHub
parent d2d9ac0280
commit 2cc580ba52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 20 deletions

View file

@ -1,39 +1,34 @@
import { useCallback } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { QueryKeys } from 'librechat-data-provider'; import { QueryKeys } from 'librechat-data-provider';
import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
import type { TMessage } from 'librechat-data-provider'; import type { TMessage } from 'librechat-data-provider';
import { useLocalize, useConversations, useConversation } from '~/hooks';
import { useDeleteConversationMutation } from '~/data-provider'; import { useDeleteConversationMutation } from '~/data-provider';
import { Dialog, DialogTrigger, Label } from '~/components/ui'; import { Dialog, DialogTrigger, Label } from '~/components/ui';
import DialogTemplate from '~/components/ui/DialogTemplate'; import DialogTemplate from '~/components/ui/DialogTemplate';
import { TrashIcon, CrossIcon } from '~/components/svg'; import { TrashIcon, CrossIcon } from '~/components/svg';
import { useLocalize, useNewConvo } from '~/hooks';
export default function DeleteButton({ conversationId, renaming, retainView, title }) { export default function DeleteButton({ conversationId, renaming, retainView, title }) {
const localize = useLocalize(); const localize = useLocalize();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { newConversation } = useConversation(); const { newConversation } = useNewConvo();
const { refreshConversations } = useConversations();
const { conversationId: currentConvoId } = useParams(); const { conversationId: currentConvoId } = useParams();
const deleteConvoMutation = useDeleteConversationMutation(); const deleteConvoMutation = useDeleteConversationMutation({
const confirmDelete = () => {
const messages = queryClient.getQueryData<TMessage[]>([QueryKeys.messages, conversationId]);
const thread_id = messages?.[messages?.length - 1]?.thread_id;
deleteConvoMutation.mutate(
{ conversationId, thread_id, source: 'button' },
{
onSuccess: () => { onSuccess: () => {
if (currentConvoId === conversationId) { if (currentConvoId === conversationId) {
newConversation(); newConversation();
} }
refreshConversations();
retainView(); retainView();
}, },
}, });
);
}; const confirmDelete = useCallback(() => {
const messages = queryClient.getQueryData<TMessage[]>([QueryKeys.messages, conversationId]);
const thread_id = messages?.[messages?.length - 1]?.thread_id;
deleteConvoMutation.mutate({ conversationId, thread_id, source: 'button' });
}, [conversationId, deleteConvoMutation, queryClient]);
return ( return (
<Dialog> <Dialog>

View file

@ -1,6 +1,6 @@
{ {
"name": "librechat-data-provider", "name": "librechat-data-provider",
"version": "0.5.2", "version": "0.5.3",
"description": "data services for librechat apps", "description": "data services for librechat apps",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.es.js", "module": "dist/index.es.js",