2023-02-06 21:17:46 -05:00
|
|
|
import React from 'react';
|
2023-02-07 10:26:19 -05:00
|
|
|
import TrashIcon from '../svg/TrashIcon';
|
2023-02-07 16:22:35 -05:00
|
|
|
import manualSWR from '~/utils/fetchers';
|
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
import { setConversation } from '~/store/convoSlice';
|
|
|
|
|
import { setMessages } from '~/store/messageSlice';
|
|
|
|
|
|
|
|
|
|
export default function DeleteButton({ conversationId }) {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const { trigger, isMutating } = manualSWR(
|
|
|
|
|
'http://localhost:3050/clear_convos',
|
|
|
|
|
'post',
|
|
|
|
|
() => {
|
|
|
|
|
dispatch(setMessages([]));
|
|
|
|
|
dispatch(setConversation({ conversationId: null, parentMessageId: null }));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const clickHandler = () => trigger({ conversationId });
|
2023-02-06 21:17:46 -05:00
|
|
|
|
|
|
|
|
return (
|
2023-02-07 16:22:35 -05:00
|
|
|
<button
|
|
|
|
|
className="p-1 hover:text-white"
|
|
|
|
|
onClick={clickHandler}
|
|
|
|
|
>
|
2023-02-07 10:26:19 -05:00
|
|
|
<TrashIcon />
|
2023-02-06 21:17:46 -05:00
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|