nova-betterchat/src/hooks/useInitialiseNewChat.ts
2023-03-04 08:29:12 +08:00

32 lines
732 B
TypeScript

import React from 'react';
import useStore from '@store/store';
import { MessageInterface } from '@type/chat';
import { defaultSystemMessage } from '@constants/chat';
const useInitialiseNewChat = () => {
const [setChats, setMessages, setCurrentChatIndex] = useStore((state) => [
state.setChats,
state.setMessages,
state.setCurrentChatIndex,
]);
const initialiseNewChat = () => {
const message: MessageInterface = {
role: 'system',
content: defaultSystemMessage,
};
setChats([
{
title: 'New Chat',
messages: [message],
},
]);
setMessages([message]);
setCurrentChatIndex(0);
};
return initialiseNewChat;
};
export default useInitialiseNewChat;