mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +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 { 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({
|
||||||
|
onSuccess: () => {
|
||||||
|
if (currentConvoId === conversationId) {
|
||||||
|
newConversation();
|
||||||
|
}
|
||||||
|
retainView();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const confirmDelete = () => {
|
const confirmDelete = useCallback(() => {
|
||||||
const messages = queryClient.getQueryData<TMessage[]>([QueryKeys.messages, conversationId]);
|
const messages = queryClient.getQueryData<TMessage[]>([QueryKeys.messages, conversationId]);
|
||||||
const thread_id = messages?.[messages?.length - 1]?.thread_id;
|
const thread_id = messages?.[messages?.length - 1]?.thread_id;
|
||||||
|
|
||||||
deleteConvoMutation.mutate(
|
deleteConvoMutation.mutate({ conversationId, thread_id, source: 'button' });
|
||||||
{ conversationId, thread_id, source: 'button' },
|
}, [conversationId, deleteConvoMutation, queryClient]);
|
||||||
{
|
|
||||||
onSuccess: () => {
|
|
||||||
if (currentConvoId === conversationId) {
|
|
||||||
newConversation();
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshConversations();
|
|
||||||
retainView();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue