mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-25 11:46:12 +01:00
refactor(client): convert ClearConvos component from jsx to tsx
refactor(client): convert Dialog, DialogButton, Input, Label, Checkbox, and DialogTemplate components from jsx to tsx refactor(client): export ClearChatsButton component from General.tsx refactor(client): add useCallback hook to moveToTop function in Nav component
This commit is contained in:
parent
c661276888
commit
931a89204c
6 changed files with 50 additions and 53 deletions
41
client/src/components/Nav/ClearConvos.tsx
Normal file
41
client/src/components/Nav/ClearConvos.tsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { Dialog, DialogTemplate } from '../ui/';
|
||||
import { ClearChatsButton } from './SettingsTabs/';
|
||||
import { useClearConversationsMutation } from '~/data-provider';
|
||||
import store from '~/store';
|
||||
|
||||
const ClearConvos = ({ open, onOpenChange }) => {
|
||||
const { newConversation } = store.useConversation();
|
||||
const { refreshConversations } = store.useConversations();
|
||||
const clearConvosMutation = useClearConversationsMutation();
|
||||
const [confirmClear, setConfirmClear] = useState(false);
|
||||
|
||||
const clearConvos = useCallback(() => {
|
||||
if (confirmClear) {
|
||||
console.log('Clearing conversations...');
|
||||
clearConvosMutation.mutate({});
|
||||
setConfirmClear(false);
|
||||
} else {
|
||||
setConfirmClear(true);
|
||||
}
|
||||
}, [confirmClear, clearConvosMutation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (clearConvosMutation.isSuccess) {
|
||||
refreshConversations();
|
||||
newConversation();
|
||||
}
|
||||
}, [clearConvosMutation.isSuccess, newConversation, refreshConversations]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogTemplate
|
||||
title="Clear conversations"
|
||||
description="Are you sure you want to clear all conversations? This is irreversible."
|
||||
leftButtons={<ClearChatsButton showText={false} confirmClear={confirmClear} onClick={clearConvos} />}
|
||||
/>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default ClearConvos;
|
||||
Loading…
Add table
Add a link
Reference in a new issue