From ac7f34fa5ee67900714121b700768ebb18b874d1 Mon Sep 17 00:00:00 2001 From: bobzel Date: Sat, 21 Sep 2024 23:26:52 -0400 Subject: added flashcard deck creator to foramtted text box. --- src/client/views/nodes/ComparisonBox.tsx | 6 +++--- src/client/views/nodes/formattedText/FormattedTextBox.tsx | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index 338604302..9d9535abd 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -116,7 +116,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() - {DocCast(this.Document.embedContainer).type_collection === 'carousel' ? null : ( + {DocCast(this.Document.embedContainer)?.type_collection === CollectionViewType.Carousel ? null : (
Create a flashcard pile
}>
this.createFlashcardPile([this.Document], false)}> @@ -688,13 +688,13 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() // (!this.dataDoc[this.fieldKey + '_0'] && this.dataDoc[this._props.fieldKey + '_0'] !== 'empty') if (!this.dataDoc[this.fieldKey + '_0'] && !this._isEmpty) { const dataSplit = StrCast(this.dataDoc.data).includes('Keyword: ') ? StrCast(this.dataDoc.data).split('Keyword: ') : StrCast(this.dataDoc.data).split('Answer: '); - const newDoc = Docs.Create.TextDocument(dataSplit[1]); + const newDoc = Docs.Create.TextDocument(dataSplit[1], { _layout_autoHeight: true }); this.addDoc(newDoc, this.fieldKey + '_0'); } if (!this.dataDoc[this.fieldKey + '_1'] && !this._isEmpty) { const dataSplit = StrCast(this.dataDoc.data).includes('Keyword: ') ? StrCast(this.dataDoc.data).split('Keyword: ') : StrCast(this.dataDoc.data).split('Answer: '); - const newDoc = Docs.Create.TextDocument(dataSplit[0]); + const newDoc = Docs.Create.TextDocument(dataSplit[0], { _layout_autoHeight: true }); this.addDoc(newDoc, this.fieldKey + '_1'); } diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index c8e020192..07a4d1093 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -213,9 +213,22 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent { + const queryText = window.getSelection()?.toString() ?? ''; + try { + if (queryText) { + const res = await gptAPICall(queryText, GPTCallType.FLASHCARD); + AnchorMenu.Instance.transferToFlashcard(res || 'Something went wrong', NumCast(this.layoutDoc.x), NumCast(this.layoutDoc.y)); + } + } catch (err) { + console.error(err); + } + }; + @action setupAnchorMenu = () => { AnchorMenu.Instance.Status = 'marquee'; + AnchorMenu.Instance.gptFlashcards = this.gptPDFFlashcards; AnchorMenu.Instance.OnClick = () => { !this.layoutDoc.layout_showSidebar && this.toggleSidebar(); setTimeout(() => this._sidebarRef.current?.anchorMenuClick(this.makeLinkAnchor(undefined, OpenWhere.addRight, undefined, 'Anchored Selection', true))); // give time for sidebarRef to be created -- cgit v1.2.3-70-g09d2