Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset current conversation #556

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add clear chat component
  • Loading branch information
uoyniXnaH committed Mar 10, 2024
commit a86c3be9ab6b1c4578cd9a7c1ed6eaf0c7bf5e0b
2 changes: 2 additions & 0 deletions src/components/Chat/ChatContent/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useSubmit from '@hooks/useSubmit';
import DownloadChat from './DownloadChat';
import CloneChat from './CloneChat';
import ShareGPT from '@components/ShareGPT';
import ClearChat from './ClearChat';

const ChatContent = () => {
const inputRole = useStore((state) => state.inputRole);
Expand Down Expand Up @@ -110,6 +111,7 @@ const ChatContent = () => {
<DownloadChat saveRef={saveRef} />
<ShareGPT />
<CloneChat />
<ClearChat />
</div>
)}
</div>
Expand Down
33 changes: 33 additions & 0 deletions src/components/Chat/ChatContent/ClearChat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import useStore from '@store/store';

import { ChatInterface } from '@type/chat';
import { _defaultSystemMessage } from '@constants/chat';

const ClearChat = React.memo(() => {
const { t } = useTranslation();

const setChats = useStore((state) => state.setChats);
const currentChatIndex = useStore((state) => state.currentChatIndex);

const clearChat = () => {
const updatedChats: ChatInterface[] = JSON.parse(
JSON.stringify(useStore.getState().chats)
);
updatedChats[currentChatIndex].messages = [{ role: 'system', content: useStore.getState().defaultSystemMessage }];
setChats(updatedChats);
};

return (
<button
className='btn btn-neutral flex gap-1'
aria-label={t('clearThisConversation') as string}
onClick={clearChat}
>
{t('resetThisConversation')}
</button>
);
});

export default ClearChat;