mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 03:40:14 +01:00
34 lines
970 B
JavaScript
34 lines
970 B
JavaScript
import React from 'react';
|
|
import TrashIcon from '../svg/TrashIcon';
|
|
import { useSWRConfig } from 'swr';
|
|
import manualSWR from '~/utils/fetchers';
|
|
import { useDispatch } from 'react-redux';
|
|
import { setNewConvo, removeAll } from '~/store/convoSlice';
|
|
import { setMessages } from '~/store/messageSlice';
|
|
|
|
export default function ClearConvos() {
|
|
const dispatch = useDispatch();
|
|
const { mutate } = useSWRConfig();
|
|
|
|
const { trigger } = manualSWR(`/api/convos/clear`, 'post', () => {
|
|
dispatch(setMessages([]));
|
|
dispatch(setNewConvo());
|
|
mutate(`/api/convos`);
|
|
});
|
|
|
|
const clickHandler = () => {
|
|
console.log('Clearing conversations...');
|
|
dispatch(removeAll());
|
|
trigger({});
|
|
};
|
|
|
|
return (
|
|
<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"
|
|
onClick={clickHandler}
|
|
>
|
|
<TrashIcon />
|
|
Clear conversations
|
|
</a>
|
|
);
|
|
}
|