From bb11e8c07f86b1ba0148f1e406a070c14e9abc7c Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 20 May 2024 15:59:52 -0400 Subject: lint cleanup and some flashcard fixes --- src/client/apis/gpt/setup.ts | 1 + src/client/util/CurrentUserUtils.ts | 3 +- src/client/views/nodes/ComparisonBox.tsx | 162 +++++++++------------ src/client/views/nodes/DocumentView.tsx | 6 +- .../views/nodes/formattedText/FormattedTextBox.tsx | 4 +- src/client/views/pdf/AnchorMenu.tsx | 10 +- 6 files changed, 80 insertions(+), 106 deletions(-) (limited to 'src') diff --git a/src/client/apis/gpt/setup.ts b/src/client/apis/gpt/setup.ts index 831c97eaa..7084f38bf 100644 --- a/src/client/apis/gpt/setup.ts +++ b/src/client/apis/gpt/setup.ts @@ -5,6 +5,7 @@ export enum GPTCallType { SUMMARY = 'summary', COMPLETION = 'completion', EDIT = 'edit', + FLASHCARD = 'flashcard', } export type GPTCallOpts = { diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index b9c4d8b5f..e095bc659 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -354,8 +354,7 @@ pie title Minerals in my tap water creator:(opts:DocumentOptions)=> any // how to create the empty thing if it doesn't exist }[] = [ {key: "Note", creator: opts => Docs.Create.TextDocument("", opts), opts: { _width: 200, _layout_autoHeight: true }}, - {key: "Flashcard", creator: opts => Docs.Create.ComparisonDocument("", opts), opts: { _layout_isFlashcard: true, _width: 300, _height: 300}}, - // {key: "Flashcard", creator: opts => Docs.Create.TextDocument("", opts), opts: { _width: 200, _layout_autoHeight: true, _layout_enableAltContentUI: true}}, + {key: "Flashcard", creator: opts => Docs.Create.ComparisonDocument("", opts), opts: { _layout_isFlashcard: true, _width: 300, _height: 300}}, {key: "Image", creator: opts => Docs.Create.ImageDocument("", opts), opts: { _width: 400, _height:400 }}, {key: "Equation", creator: opts => Docs.Create.EquationDocument("",opts), opts: { _width: 300, _height: 35, }}, {key: "Noteboard", creator: opts => Docs.Create.NoteTakingDocument([], opts), opts: { _width: 250, _height: 200, _layout_fitWidth: true}}, diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index 84d14d4ef..5dd3cc9b0 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -170,9 +170,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() e, moveEv => { const de = new DragManager.DocumentDragData([DocCast(this.dataDoc[which])], dropActionType.move); - de.moveDocument = (doc: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (doc: Doc | Doc[]) => boolean): boolean => { - return addDocument(doc); - }; + de.moveDocument = (doc: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (doc: Doc | Doc[]) => boolean): boolean => addDocument(doc); de.canEmbed = true; DragManager.StartDocumentDrag([this._closeRef.current!], de, moveEv.clientX, moveEv.clientY); return true; @@ -235,7 +233,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() * Changes the view option to hover for a flashcard. */ hoverFlip = (side: string | undefined) => { - if (this.layoutDoc[`_${this._props.fieldKey}_revealOp`] == 'hover') this.layoutDoc[`_${this._props.fieldKey}_usePath`] = side; + if (this.layoutDoc[`_${this._props.fieldKey}_revealOp`] === 'hover') this.layoutDoc[`_${this._props.fieldKey}_usePath`] = side; }; /** @@ -248,12 +246,12 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent()
- setupMoveUpEvents(e.target, e, returnFalse, emptyFunction, e => { + setupMoveUpEvents(e.target, e, returnFalse, emptyFunction, () => { console.log(this.layoutDoc[`_${this._props.fieldKey}_revealOp`]); - if (!this.layoutDoc[`_${this._props.fieldKey}_revealOp`] || this.layoutDoc[`_${this._props.fieldKey}_revealOp`] == 'flip') { + if (!this.layoutDoc[`_${this._props.fieldKey}_revealOp`] || this.layoutDoc[`_${this._props.fieldKey}_revealOp`] === 'flip') { this.flipFlashcard(); - console.log('Print Front of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); - console.log('Print Back of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); + console.log('Print Front of cards: ' + (RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text ?? '')); + console.log('Print Back of cards: ' + (RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text ?? '')); } }) } @@ -289,7 +287,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() const queryText = questionText + ' UserAnswer: ' + this.inputValue + '. ' + rubricText; try { - let res = await gptAPICall(queryText, GPTCallType.QUIZ); + const res = await gptAPICall(queryText, GPTCallType.QUIZ); if (!res) { console.error('GPT call failed'); return; @@ -302,19 +300,17 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() }; render() { - const clearButton = (which: string) => { - return ( - remove
}> -
this.closeDown(e, which)} // prevent triggering slider movement in registerSliding - > - -
- - ); - }; + const clearButton = (which: string) => ( + remove}> +
this.closeDown(e, which)} // prevent triggering slider movement in registerSliding + > + +
+
+ ); const displayDoc = (whichSlot: string) => { const whichDoc = DocCast(this.dataDoc[whichSlot]); const targetDoc = DocCast(whichDoc?.annotationOn, whichDoc); @@ -334,9 +330,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() moveDocument={whichSlot.endsWith('1') ? this.moveDoc1 : this.moveDoc2} removeDocument={whichSlot.endsWith('1') ? this.remDoc1 : this.remDoc2} NativeWidth={() => NumCast(this.layoutDoc.width, 200)} - NativeHeight={(): number => { - return NumCast(this.layoutDoc.height, 200); - }} + NativeHeight={(): number => NumCast(this.layoutDoc.height, 200)} isContentActive={emptyFunction} isDocumentActive={returnFalse} whenChildContentsActiveChanged={this.whenChildContentsActiveChanged} @@ -358,112 +352,90 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() ); - const displayBoxReveal = (which: string, which2: string, index: number, cover: number) => { - return ( -
-
this.registerSliding(e, cover)} - ref={ele => this.createDropTarget(ele, which, 0)}> - {displayDoc(which)} -
-
this.registerSliding(e, cover)} - ref={ele => this.createDropTarget(ele, which2, 1)}> - {displayDoc(which2)} -
-
- ); - }; - if (this.Document._layout_isFlashcard) { const side = this.layoutDoc[`_${this._props.fieldKey}_usePath`] === 'alternate' ? 1 : 0; // add text box to each side when comparison box is first created - if (!(this.dataDoc[this.fieldKey + '_0'] || this.dataDoc[this.fieldKey + '_0'] == 'empty')) { + if (!(this.dataDoc[this.fieldKey + '_0'] || this.dataDoc[this.fieldKey + '_0'] === 'empty')) { const dataSplit = StrCast(this.dataDoc.data).split('Answer'); const newDoc = Docs.Create.TextDocument(dataSplit[1]); // if there is text from the pdf ai cards, put the question on the front side. + // eslint-disable-next-line prefer-destructuring newDoc[DocData].text = dataSplit[1]; this.addDoc(newDoc, this.fieldKey + '_0'); } - if (!(this.dataDoc[this.fieldKey + '_1'] || this.dataDoc[this.fieldKey + '_1'] == 'empty')) { + if (!(this.dataDoc[this.fieldKey + '_1'] || this.dataDoc[this.fieldKey + '_1'] === 'empty')) { const dataSplit = StrCast(this.dataDoc.data).split('Answer'); const newDoc = Docs.Create.TextDocument(dataSplit[0]); // if there is text from the pdf ai cards, put the answer on the alternate side. + // eslint-disable-next-line prefer-destructuring newDoc[DocData].text = dataSplit[0]; this.addDoc(newDoc, this.fieldKey + '_1'); } // render the QuizCards - if (DocCast(this.Document.embedContainer) && DocCast(this.Document.embedContainer)[`filterOp`] == 'quiz') { + if (DocCast(this.Document.embedContainer) && DocCast(this.Document.embedContainer).filterOp === 'quiz') { return (

{StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text)}

{/* {StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text)} */} -
- { -