diff options
author | alyssaf16 <alyssa_feinberg@brown.edu> | 2024-09-29 15:54:49 -0400 |
---|---|---|
committer | alyssaf16 <alyssa_feinberg@brown.edu> | 2024-09-29 15:54:49 -0400 |
commit | ef2a1037a418ad9fa35d6c60feba914d828d5b84 (patch) | |
tree | 311081f05d6fba0d9d023168b4e11c9e6f7d66f1 /src/client/views/nodes/ComparisonBox.tsx | |
parent | fa10d872b2a63f5a53461c8fb5473706e78af4e9 (diff) |
clean up
Diffstat (limited to 'src/client/views/nodes/ComparisonBox.tsx')
-rw-r--r-- | src/client/views/nodes/ComparisonBox.tsx | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index a410f4994..df127f0d5 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -246,8 +246,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() remDoc = (doc: Doc, which: string) => { if (this.dataDoc[which] === doc) { this._isEmpty = true; - // this.dataDoc[which] = 'empty'; - console.log('HEREEEE'); this.dataDoc[which] = undefined; return true; } @@ -302,7 +300,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() this._animating = 'all 200ms'; // on click, animate slider movement to the targetWidth this.layoutDoc[this.clipWidthKey] = (targetWidth * 100) / this._props.PanelWidth(); - // this.layoutDoc[this.clipHeightKey] = (targetWidth * 100) / this._props.PanelHeight(); setTimeout( action(() => { @@ -384,6 +381,24 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() console.log('RESPONSE: ' + response.data['transcription']); }; + getYouTubeVideoId = (url: string) => { + const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/; + const match = url.match(regExp); + return match && match[2].length === 11 ? match[2] : null; + }; + + youtubeUpload = async () => { + const audio = { + file: this.getYouTubeVideoId(StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text)), + }; + const response = await axios.post('http://localhost:105/youtube/', audio, { + headers: { + 'Content-Type': 'application/json', + }, + }); + return response.data['transcription']; + }; + createFlashcardPile(collectionArr: Doc[], gpt: boolean) { const newCol = Docs.Create.CarouselDocument(collectionArr, { _width: NumCast(this.layoutDoc['_' + this._props.fieldKey + '_width'], 250) + 50, @@ -394,6 +409,9 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() newCol['x'] = this.layoutDoc['x']; newCol['y'] = NumCast(this.layoutDoc['y']) + 50; newCol.type_collection = 'carousel'; + for (var i = 0; i < collectionArr.length; i++) { + DocCast(collectionArr[i])[DocData].embedContainer = newCol; + } if (gpt) { this._props.DocumentView?.()._props.addDocument?.(newCol); @@ -405,6 +423,9 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() } } + /** + * Transfers the content of flashcards into a flashcard pile. + */ gptFlashcardPile = async () => { var text = await this.askGPT(GPTCallType.STACK); var senArr = text?.split('Question: '); @@ -441,17 +462,28 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() DocCast(newDoc)[DocData][this.fieldKey + '_1'] = textDoc1; DocCast(newDoc)[DocData][this.fieldKey + '_0'] = Docs.Create.TextDocument(question[0].includes('Answer: ') ? question[0].split('Answer: ')[1] : question[1]); } + collectionArr.push(newDoc); } this.createFlashcardPile(collectionArr, true); }; + /** + * Calls GPT for each flashcard type. + */ askGPT = async (callType: GPTCallType): Promise<string | undefined> => { - const questionText = 'Question: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); + let questionText = 'Question: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); const rubricText = ' Rubric: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); const queryText = questionText + ' UserAnswer: ' + this._inputValue + '. ' + rubricText; this._loading = true; const doc = DocCast(this.dataDoc[this.props.fieldKey + '_0']); + + // if (true) { + // const s = await this.youtubeUpload(); + + // questionText = 'Question: ' + s; + // } + if (callType == GPTCallType.CHATCARD) { if (StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text) === '') { this._loading = false; @@ -461,7 +493,7 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() } try { console.log(queryText); - const res = await gptAPICall(callType == GPTCallType.QUIZ ? queryText : questionText, callType); + const res = await gptAPICall(questionText, GPTCallType.FLASHCARD); if (!res) { console.error('GPT call failed'); return; @@ -647,7 +679,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() const clearButton = (which: string) => ( <Tooltip title={<div className="dash-tooltip">remove</div>}> <div - // style={{ position: 'relative', top: '0px', left: '10px' }} ref={this._closeRef} className={`clear-button ${which}`} onPointerDown={e => this.closeDown(e, which)} // prevent triggering slider movement in registerSliding @@ -660,18 +691,13 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() const whichDoc = DocCast(this.dataDoc[whichSlot]); const targetDoc = DocCast(whichDoc?.annotationOn, whichDoc); const layoutString = targetDoc ? '' : this.testForTextFields(whichSlot); - // whichDoc['backgroundColor'] = this.layoutDoc['backgroundColor']; return targetDoc || layoutString ? ( - // <MathJaxContext config={this.mathJaxConfig}> - // <MathJax> <> <DocumentView // eslint-disable-next-line react/jsx-props-no-spreading {...this._props} fitWidth={undefined} - NativeHeight={returnZero} - NativeWidth={returnZero} ignoreUsePath={layoutString ? true : undefined} renderDepth={this.props.renderDepth + 1} LayoutTemplateString={layoutString} @@ -679,6 +705,8 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() containerViewPath={this._props.docViewPath} moveDocument={whichSlot.endsWith('1') ? this.moveDoc1 : this.moveDoc2} removeDocument={whichSlot.endsWith('1') ? this.remDoc1 : this.remDoc2} + NativeWidth={this.layoutWidth} + NativeHeight={this.layoutHeight} isContentActive={() => this.childActive} isDocumentActive={returnFalse} dontSelect={returnTrue} @@ -687,9 +715,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() hideLinkButton pointerEvents={this.childActive ? undefined : returnNone} /> - {/* </MathJax> */} - {/* <div style={{ position: 'absolute', top: '-5px', left: '2px' }}>{layoutString ? null : clearButton(whichSlot)}</div> */} - {/* </MathJaxContext> // placeholder image if doc is missingleft: `${NumCast(this.layoutDoc.width, 200) - 33}px` */} </> ) : ( <div className="placeholder"> @@ -708,7 +733,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() }} ref={ele => this.createDropTarget(ele, which, index)}> {!this._isEmpty ? displayDoc(which) : null} - {/* {this.dataDoc[this.fieldKey + '_0'] !== 'empty' ? displayDoc(which) : null} */} </div> ); @@ -716,7 +740,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() const side = this.frontSide ? 1 : 0; // add text box to each side when comparison box is first created - // (!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]); |