mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 21:23:58 +01:00
chat naming improvements
This commit is contained in:
parent
35f52ea005
commit
8bfe692a40
24
src/App.tsx
24
src/App.tsx
|
@ -8,7 +8,8 @@ import ConfigMenu from './components/ConfigMenu';
|
||||||
import useSaveToLocalStorage from '@hooks/useSaveToLocalStorage';
|
import useSaveToLocalStorage from '@hooks/useSaveToLocalStorage';
|
||||||
import useUpdateCharts from '@hooks/useUpdateChats';
|
import useUpdateCharts from '@hooks/useUpdateChats';
|
||||||
|
|
||||||
import { ChatInterface } from '@type/chat';
|
import { ChatInterface, MessageInterface } from '@type/chat';
|
||||||
|
import { defaultSystemMessage } from '@constants/chat';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
useSaveToLocalStorage();
|
useSaveToLocalStorage();
|
||||||
|
@ -20,15 +21,34 @@ function App() {
|
||||||
state.setCurrentChatIndex,
|
state.setCurrentChatIndex,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const initialiseNewChat = () => {
|
||||||
|
const message: MessageInterface = {
|
||||||
|
role: 'system',
|
||||||
|
content: defaultSystemMessage,
|
||||||
|
};
|
||||||
|
setChats([
|
||||||
|
{
|
||||||
|
title: 'New Chat',
|
||||||
|
messages: [message],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
setMessages([message]);
|
||||||
|
setCurrentChatIndex(0);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// localStorage.removeItem('chats');
|
// localStorage.removeItem('chats');
|
||||||
const storedChats = localStorage.getItem('chats');
|
const storedChats = localStorage.getItem('chats');
|
||||||
if (storedChats) {
|
if (storedChats) {
|
||||||
try {
|
try {
|
||||||
const chats: ChatInterface[] = JSON.parse(storedChats);
|
const chats: ChatInterface[] = JSON.parse(storedChats);
|
||||||
|
if (chats.length > 0) {
|
||||||
setChats(chats);
|
setChats(chats);
|
||||||
setMessages(chats[0].messages);
|
setMessages(chats[0].messages);
|
||||||
setCurrentChatIndex(0);
|
setCurrentChatIndex(0);
|
||||||
|
} else {
|
||||||
|
initialiseNewChat();
|
||||||
|
}
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
setChats([]);
|
setChats([]);
|
||||||
setMessages([]);
|
setMessages([]);
|
||||||
|
@ -36,7 +56,7 @@ function App() {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setChats([]);
|
initialiseNewChat();
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -98,12 +98,12 @@ const ChatContent = () => {
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
</button>
|
</button>
|
||||||
<button className='btn btn-neutral border-0 md:border mt-2'>
|
{/* <button className='btn btn-neutral border-0 md:border mt-2'>
|
||||||
<div className='flex items-center justify-center gap-2'>
|
<div className='flex items-center justify-center gap-2'>
|
||||||
<RefreshIcon />
|
<RefreshIcon />
|
||||||
Regenerate response
|
Regenerate response
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button> */}
|
||||||
</div>
|
</div>
|
||||||
<div className='w-full h-32 md:h-48 flex-shrink-0'></div>
|
<div className='w-full h-32 md:h-48 flex-shrink-0'></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,8 +26,16 @@ const NewMessageButton = ({ messageIndex }: { messageIndex: number }) => {
|
||||||
const addChat = () => {
|
const addChat = () => {
|
||||||
if (chats) {
|
if (chats) {
|
||||||
const updatedChats: ChatInterface[] = JSON.parse(JSON.stringify(chats));
|
const updatedChats: ChatInterface[] = JSON.parse(JSON.stringify(chats));
|
||||||
|
let titleIndex = 1;
|
||||||
|
let title = `New Chat ${titleIndex}`;
|
||||||
|
|
||||||
|
while (chats.some((chat) => chat.title === title)) {
|
||||||
|
titleIndex += 1;
|
||||||
|
title = `New Chat ${titleIndex}`;
|
||||||
|
}
|
||||||
|
|
||||||
updatedChats.unshift({
|
updatedChats.unshift({
|
||||||
title: `Chat ${Math.random()}`,
|
title,
|
||||||
messages: [{ role: 'system', content: defaultSystemMessage }],
|
messages: [{ role: 'system', content: defaultSystemMessage }],
|
||||||
});
|
});
|
||||||
setChats(updatedChats);
|
setChats(updatedChats);
|
||||||
|
|
|
@ -19,8 +19,16 @@ const NewChat = () => {
|
||||||
const addChat = () => {
|
const addChat = () => {
|
||||||
if (chats) {
|
if (chats) {
|
||||||
const updatedChats: ChatInterface[] = JSON.parse(JSON.stringify(chats));
|
const updatedChats: ChatInterface[] = JSON.parse(JSON.stringify(chats));
|
||||||
|
let titleIndex = 1;
|
||||||
|
let title = `New Chat ${titleIndex}`;
|
||||||
|
|
||||||
|
while (chats.some((chat) => chat.title === title)) {
|
||||||
|
titleIndex += 1;
|
||||||
|
title = `New Chat ${titleIndex}`;
|
||||||
|
}
|
||||||
|
|
||||||
updatedChats.unshift({
|
updatedChats.unshift({
|
||||||
title: `Chat ${Math.random()}`,
|
title,
|
||||||
messages: [{ role: 'system', content: defaultSystemMessage }],
|
messages: [{ role: 'system', content: defaultSystemMessage }],
|
||||||
});
|
});
|
||||||
setChats(updatedChats);
|
setChats(updatedChats);
|
||||||
|
|
Loading…
Reference in a new issue