| import { useCallback } from 'react'; |
| import { useNotebookStore } from '@/store/notebookStore'; |
| import { useAIChatStore } from '@/store/aiChatStore'; |
|
|
| |
|
|
| export function useOpenAIInNotebook() { |
| const { setNotebookVisible, setNotebookActiveTab } = useNotebookStore(); |
| const { setActiveConversation, createConversation } = useAIChatStore(); |
|
|
| const openAIInNotebook = useCallback( |
| async (options?: { |
| conversationId?: string; |
| bookHash?: string; |
| newConversationTitle?: string; |
| }) => { |
| |
| setNotebookVisible(true); |
| setNotebookActiveTab('ai'); |
|
|
| if (options?.conversationId) { |
| |
| await setActiveConversation(options.conversationId); |
| } else if (options?.bookHash && options?.newConversationTitle) { |
| |
| await createConversation(options.bookHash, options.newConversationTitle); |
| } |
| }, |
| [setNotebookVisible, setNotebookActiveTab, setActiveConversation, createConversation], |
| ); |
|
|
| const closeAIInNotebook = useCallback(() => { |
| setNotebookActiveTab('notes'); |
| }, [setNotebookActiveTab]); |
|
|
| return { |
| openAIInNotebook, |
| closeAIInNotebook, |
| }; |
| } |
|
|
| export default useOpenAIInNotebook; |
|
|