Skip to content

Commit

Permalink
✨ feat: add setChats hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours committed Jul 30, 2024
1 parent b6bd682 commit c8ebb73
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ProChat/hooks/useProChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export interface ProChatInstance
* @returns void
*/
pushChat: (chats: { id?: string; content: string; role: string; [key: string]: any }) => void;
/**
* 往数据流中推送消息
* @returns void
*/
setChat: (
id: string,
chats: { id?: string; content?: string; role?: string; [key: string]: any },
) => void;
/**
* 获取当前聊天消息列表
* @returns ChatMessage[]
Expand Down Expand Up @@ -77,6 +85,14 @@ export const useProChat = () => {
message: chat?.content,
});
});
const setChat = useRefFunction((id, chat) => {
return dispatchMessage({
...chat,
type: 'updateMessage',
id,
value: chat?.content,
});
});
const getChatMessages = useRefFunction(() => chatSelectors.currentChats(storeApi.getState()));

const setMessageContent = useRefFunction((id: string, content: string) => {
Expand All @@ -98,6 +114,7 @@ export const useProChat = () => {
getChatById,
getChats,
pushChat,
setChat,
getChatMessages,
resendMessage,
sendMessage,
Expand Down

0 comments on commit c8ebb73

Please sign in to comment.