From 737efc3e6cada537536c7bc5e46f5b57970da276 Mon Sep 17 00:00:00 2001 From: bobzel Date: Fri, 11 Oct 2024 22:01:50 -0400 Subject: Lots of cleanup in comparisonBox to get rid of duplicated code and siimplify long functions. Utility functions were added to ComparisonBox to simplify menu functions, and to FormattedTextBox to simplify creating centered text views. --- src/client/views/pdf/AnchorMenu.tsx | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'src/client/views/pdf') diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index 7243473e0..5ab9b556c 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -10,7 +10,6 @@ import { emptyFunction, unimplementedFunction } from '../../../Utils'; import { Doc, Opt } from '../../../fields/Doc'; import { DocData } from '../../../fields/DocSymbols'; import { GPTCallType, gptAPICall } from '../../apis/gpt/GPT'; -import { Docs } from '../../documents/Documents'; import { SettingsManager } from '../../util/SettingsManager'; import { undoBatch } from '../../util/UndoManager'; import { AntimodeMenu, AntimodeMenuProps } from '../AntimodeMenu'; @@ -19,6 +18,7 @@ import { DocumentView } from '../nodes/DocumentView'; import { DrawingOptions, SmartDrawHandler } from '../smartdraw/SmartDrawHandler'; import './AnchorMenu.scss'; import { GPTPopup, GPTPopupMode } from './GPTPopup/GPTPopup'; +import { ComparisonBox } from '../nodes/ComparisonBox'; @observer export class AnchorMenu extends AntimodeMenu { @@ -117,29 +117,15 @@ export class AnchorMenu extends AntimodeMenu { */ transferToFlashcard = (text: string, x: number, y: number) => { - // put each question generated by GPT on the front of the flashcard - const senArr = text.trim().split('Question:'); - const collectionArr: Doc[] = []; - for (let i = 1; i < senArr.length; i++) { - const newDoc = Docs.Create.ComparisonDocument(senArr[i], { _layout_isFlashcard: true, _width: 300, _height: 300 }); - newDoc.text = senArr[i]; - - collectionArr.push(newDoc); - } - // create a new carousel collection of these flashcards - const newCol = Docs.Create.CarouselDocument(collectionArr, { - _width: 250, - _height: 200, - _layout_fitWidth: false, - _layout_autoHeight: true, - }); - - newCol.x = x; - newCol.y = y; - newCol.zIndex = 1000; - - this.addToCollection?.(newCol); - this._loading = false; + ComparisonBox.createFlashcardDeck(text, 250, 200, 'data_front', 'data_back').then( + action(newCol => { + newCol.x = x; + newCol.y = y; + newCol.zIndex = 1000; + this.addToCollection?.(newCol); + this._loading = false; + }) + ); }; /** -- cgit v1.2.3-70-g09d2