2023-02-07 19:07:48 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
import TrashIcon from '../svg/TrashIcon';
|
2023-02-13 13:32:54 -05:00
|
|
|
import { useSWRConfig } from "swr"
|
2023-02-07 19:07:48 -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 ClearConvos() {
|
|
|
|
|
const dispatch = useDispatch();
|
2023-02-13 13:32:54 -05:00
|
|
|
const { mutate } = useSWRConfig()
|
2023-02-07 19:07:48 -05:00
|
|
|
|
2023-03-04 17:39:06 -05:00
|
|
|
const { trigger } = manualSWR(
|
2023-03-06 14:04:06 -05:00
|
|
|
`http://api:3080/convos/clear`,
|
2023-02-07 19:07:48 -05:00
|
|
|
'post',
|
|
|
|
|
() => {
|
|
|
|
|
dispatch(setMessages([]));
|
2023-02-13 15:58:35 -05:00
|
|
|
dispatch(setConversation({ error: false, title: 'New chat', conversationId: null, parentMessageId: null }));
|
2023-03-06 14:04:06 -05:00
|
|
|
mutate(`http://api:3080/convos`);
|
2023-02-07 19:07:48 -05:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-02-08 00:02:29 -05:00
|
|
|
const clickHandler = () => {
|
|
|
|
|
console.log('Clearing conversations...');
|
|
|
|
|
trigger({});
|
|
|
|
|
};
|
2023-02-07 19:07:48 -05:00
|
|
|
|
|
|
|
|
return (
|
2023-02-08 08:27:23 -05:00
|
|
|
<a
|
|
|
|
|
className="flex cursor-pointer items-center gap-3 rounded-md py-3 px-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10"
|
2023-02-07 19:07:48 -05:00
|
|
|
onClick={clickHandler}
|
2023-02-08 08:27:23 -05:00
|
|
|
>
|
|
|
|
|
<TrashIcon />
|
|
|
|
|
Clear conversations
|
|
|
|
|
</a>
|
2023-02-07 19:07:48 -05:00
|
|
|
);
|
|
|
|
|
}
|