From f0807c6f6c31ac9ae2e6fb581f19a760f8e5687e Mon Sep 17 00:00:00 2001 From: sharkiecodes Date: Wed, 2 Jul 2025 20:33:37 -0400 Subject: Implementing replacement of GPTPopup --- .../nodes/chatbot/chatboxcomponents/ChatBox.tsx | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/client/views/nodes/chatbot/chatboxcomponents') diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx index 636b77b38..f84a4cd2a 100644 --- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx +++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx @@ -111,8 +111,16 @@ export class ChatBox extends ViewBoxAnnotatableComponent() { super(props); makeObservable(this); + // At mount time, find the DocumentView whose .Document is the collection container. + const parentView = DocumentView.Selected().lastElement(); + if (!parentView) { + console.warn("GPT ChatBox not inside a DocumentView – cannot sort."); + } + + + this.messagesRef = React.createRef(); - this.docManager = new AgentDocumentManager(this); + this.docManager = new AgentDocumentManager(this, parentView); // Initialize OpenAI client this.initializeOpenAI(); @@ -154,6 +162,25 @@ export class ChatBox extends ViewBoxAnnotatableComponent() { } ); + /* + reaction( + () => ({ selDoc: DocumentView.Selected().lastElement(), visible: SnappingManager.ChatVisible }), + ({ selDoc, visible }) => { + const hasChildDocs = visible && selDoc?.ComponentView?.hasChildDocs; + if (hasChildDocs) { + this._textToDocMap.clear(); + this.setCollectionContext(selDoc.Document); + this.onGptResponse = (sortResult: string, questionType: GPTDocCommand) => this.processGptResponse(selDoc, this._textToDocMap, sortResult, questionType); + this.onQuizRandom = () => this.randomlyChooseDoc(selDoc.Document, hasChildDocs()); + this._documentDescriptions = Promise.all(hasChildDocs().map(doc => + Doc.getDescription(doc).then(text => this._textToDocMap.set(text.replace(/\n/g, ' ').trim(), doc) && `${DescriptionSeperator}${text}${DescriptionSeperator}`) + )).then(docDescriptions => docDescriptions.join()); // prettier-ignore + } + }, + { fireImmediately: true } + ); + }*/ + // Initialize font size from saved preference this.initFontSize(); } -- cgit v1.2.3-70-g09d2