nova-betterchat/src/hooks/useInitialiseNewChat.ts

32 lines
732 B
TypeScript
Raw Normal View History

2023-03-04 01:29:12 +01:00
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;