mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
*️⃣ 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:
parent
d2d9ac0280
commit
2cc580ba52
2 changed files with 15 additions and 20 deletions
|
|
@ -1,39 +1,34 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { QueryKeys } from 'librechat-data-provider';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import { useLocalize, useConversations, useConversation } from '~/hooks';
|
||||
import { useDeleteConversationMutation } from '~/data-provider';
|
||||
import { Dialog, DialogTrigger, Label } from '~/components/ui';
|
||||
import DialogTemplate from '~/components/ui/DialogTemplate';
|
||||
import { TrashIcon, CrossIcon } from '~/components/svg';
|
||||
import { useLocalize, useNewConvo } from '~/hooks';
|
||||
|
||||
export default function DeleteButton({ conversationId, renaming, retainView, title }) {
|
||||
const localize = useLocalize();
|
||||
const queryClient = useQueryClient();
|
||||
const { newConversation } = useConversation();
|
||||
const { refreshConversations } = useConversations();
|
||||
const { newConversation } = useNewConvo();
|
||||
const { conversationId: currentConvoId } = useParams();
|
||||
const deleteConvoMutation = useDeleteConversationMutation();
|
||||
const deleteConvoMutation = useDeleteConversationMutation({
|
||||
onSuccess: () => {
|
||||
if (currentConvoId === conversationId) {
|
||||
newConversation();
|
||||
}
|
||||
retainView();
|
||||
},
|
||||
});
|
||||
|
||||
const confirmDelete = () => {
|
||||
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' },
|
||||
{
|
||||
onSuccess: () => {
|
||||
if (currentConvoId === conversationId) {
|
||||
newConversation();
|
||||
}
|
||||
|
||||
refreshConversations();
|
||||
retainView();
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
deleteConvoMutation.mutate({ conversationId, thread_id, source: 'button' });
|
||||
}, [conversationId, deleteConvoMutation, queryClient]);
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "librechat-data-provider",
|
||||
"version": "0.5.2",
|
||||
"version": "0.5.3",
|
||||
"description": "data services for librechat apps",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.es.js",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue