From e5cb67b92d9b3c84dc90b1e64cc7128621523801 Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Sun, 11 May 2025 13:51:58 -0400 Subject: feat: improved text from document popup --- .../nodes/chatbot/chatboxcomponents/ChatBox.tsx | 54 +++++++++++++++++----- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx') diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx index 34a1ade2e..6349e554e 100644 --- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx +++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx @@ -679,12 +679,8 @@ export class ChatBox extends ViewBoxAnnotatableComponent() { this.handleOtherChunkTypes(foundChunk, citation, doc); } else { // Show the chunk text in citation popup - let chunkText = foundChunk.text || 'Text content not available'; - - this._citationPopup = { - text: chunkText, - visible: true, - }; + let chunkText = citation.direct_text || 'Text content not available'; + this.showCitationPopup(chunkText); // Also navigate to the document DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {}); @@ -843,7 +839,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent() { break; case CHUNK_TYPE.TEXT: this._citationPopup = { text: citation.direct_text ?? 'No text available', visible: true }; - setTimeout(() => (this._citationPopup.visible = false), 3000); + this.startCitationPopupTimer(); DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => { const firstView = Array.from(doc[DocViews])[0] as DocumentView; @@ -1100,7 +1096,36 @@ export class ChatBox extends ViewBoxAnnotatableComponent() { ); /** - * Renders the chat interface, including the message list, input field, and other UI elements. + * Shows the citation popup with the given text. + * @param text The text to display in the popup. + */ + @action + showCitationPopup = (text: string) => { + this._citationPopup = { + text: text || 'No text available', + visible: true, + }; + this.startCitationPopupTimer(); + }; + + /** + * Closes the citation popup. + */ + @action + closeCitationPopup = () => { + this._citationPopup.visible = false; + }; + + /** + * Starts the auto-close timer for the citation popup. + */ + startCitationPopupTimer = () => { + // Auto-close the popup after 5 seconds + setTimeout(() => this.closeCitationPopup(), 5000); + }; + + /** + * Main render method for the ChatBox */ render() { const fontSizeClass = `font-size-${this._fontSize}`; @@ -1191,9 +1216,16 @@ export class ChatBox extends ViewBoxAnnotatableComponent() { {/* Popup for citation */} {this._citationPopup.visible && (
-

- Text from your document: {this._citationPopup.text} -

+
+ Text from your document + +
+
{this._citationPopup.text}
)} -- cgit v1.2.3-70-g09d2