Spaces:
Runtime error
Runtime error
File size: 1,260 Bytes
3b6afc0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import { useEffect } from 'react';
import TrashIcon from '../svg/TrashIcon';
import CrossIcon from '../svg/CrossIcon';
import { useRecoilValue } from 'recoil';
import { useDeleteConversationMutation } from '@librechat/data-provider';
import store from '~/store';
export default function DeleteButton({ conversationId, renaming, cancelHandler, retainView }) {
const currentConversation = useRecoilValue(store.conversation) || {};
const { newConversation } = store.useConversation();
const { refreshConversations } = store.useConversations();
const deleteConvoMutation = useDeleteConversationMutation(conversationId);
useEffect(() => {
if (deleteConvoMutation.isSuccess) {
if (currentConversation?.conversationId == conversationId) {
newConversation();
}
refreshConversations();
retainView();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [deleteConvoMutation.isSuccess]);
const clickHandler = () => {
deleteConvoMutation.mutate({ conversationId, source: 'button' });
};
const handler = renaming ? cancelHandler : clickHandler;
return (
<button className="p-1 hover:text-white" onClick={handler}>
{renaming ? <CrossIcon /> : <TrashIcon />}
</button>
);
}
|