add delete conversation mutation, fix withAuthentication on post requests

This commit is contained in:
Daniel D Orlando 2023-04-03 12:39:00 -07:00
parent bd53b878d4
commit 94e0636b32
5 changed files with 68 additions and 49 deletions

View file

@ -1,8 +1,8 @@
import React from 'react';
import { useEffect } from 'react';
import TrashIcon from '../svg/TrashIcon';
import CrossIcon from '../svg/CrossIcon';
import manualSWR from '~/utils/fetchers';
import { useRecoilValue } from 'recoil';
import { useDeleteConversationMutation } from '~/data-provider';
import store from '~/store';
@ -10,13 +10,23 @@ export default function DeleteButton({ conversationId, renaming, cancelHandler,
const currentConversation = useRecoilValue(store.conversation) || {};
const { newConversation } = store.useConversation();
const { refreshConversations } = store.useConversations();
const { trigger } = manualSWR(`/api/convos/clear`, 'post', () => {
if (currentConversation?.conversationId == conversationId) newConversation();
refreshConversations();
retainView();
});
const clickHandler = () => trigger({ conversationId, source: 'button' });
const deleteConvoMutation = useDeleteConversationMutation(conversationId);
useEffect(() => {
if(deleteConvoMutation.isSuccess) {
if (currentConversation?.conversationId == conversationId) newConversation();
refreshConversations();
retainView();
}
}, [deleteConvoMutation.isSuccess]);
const clickHandler = () => {
deleteConvoMutation.mutate({conversationId, source: 'button' });
};
const handler = renaming ? cancelHandler : clickHandler;
return (