From 4ba23252ca23a6017974c31364d00c0a1859e45e Mon Sep 17 00:00:00 2001
From: aidahosa1 <aisosa_idahosa@brown.edu>
Date: Tue, 17 Sep 2024 08:44:47 -0400
Subject: cleaning up

---
 src/client/views/pdf/GPTPopup/GPTPopup.tsx | 109 +++++++----------------------
 1 file changed, 25 insertions(+), 84 deletions(-)

(limited to 'src/client/views/pdf/GPTPopup/GPTPopup.tsx')

diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
index 1b44508d7..2d8547dcd 100644
--- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx
+++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
@@ -205,62 +205,42 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
         const selected = DocumentView.SelectedDocs().lastElement();
 
 
-                const questionText = 'Question: ' + StrCast(selected['gptInputText']);
-
-                if (StrCast(selected['gptRubric']) === '') {
-                    const rubricText = 'Rubric: ' + await this.generateRubric(StrCast(selected['gptInputText']), selected)
-                }
-
-                const rubricText = 'Rubric: ' + (StrCast(selected['gptRubric']))
-                // const rubricText = 'Rubric: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text);
-                const queryText = questionText + ' UserAnswer: ' + this.quizAnswer + '. ' + 'Rubric' + rubricText;
-
-                try {
-                    const res = await gptAPICall(queryText, GPTCallType.QUIZ);
-                    if (!res) {
-                        console.error('GPT call failed');
-                        return;
-                    }
-                    console.log(res)
-                    this.setQuizResp(res)
-                    this.conversationArray.push(res)
-
-                    this.setLoading(false);
-                    this.setSortDone(true);
-
-                    // this._outputValue = res;
-                } catch (err) {
-                    console.error('GPT call failed');
-                }
-
-
-                if (this.onQuizRandom){
-                    this.onQuizRandom()
-                }
+        const questionText = 'Question: ' + StrCast(selected['gptInputText']);
 
+        if (StrCast(selected['gptRubric']) === '') {
+            const rubricText = 'Rubric: ' + await this.generateRubric(StrCast(selected['gptInputText']), selected)
+        }
 
-            
+        const rubricText = 'Rubric: ' + (StrCast(selected['gptRubric']))
+        const queryText = questionText + ' UserAnswer: ' + this.quizAnswer + '. ' + 'Rubric' + rubricText;
 
+        try {
+            const res = await gptAPICall(queryText, GPTCallType.QUIZ);
+            if (!res) {
+                console.error('GPT call failed');
+                return;
+            }
+            console.log(res)
+            this.setQuizResp(res)
+            this.conversationArray.push(res)
 
-        // switch(quizType){
-        //     default:
-                
-        // }
+            this.setLoading(false);
+            this.setSortDone(true);
 
+        } catch (err) {
+            console.error('GPT call failed');
+        }
 
-        
 
+        if (this.onQuizRandom){
+            this.onQuizRandom()
+        }
 
     }
 
     generateRubric = async (inputText: string, doc:Doc) => {
         try {
-            const res = await gptAPICall(inputText, GPTCallType.RUBRIC);
-            console.log(res + "rubbbb")
-            // if (!res) {
-            //     console.error('GPT call failed');
-            //     return;
-            // }
+            const res = await gptAPICall(inputText, GPTCallType.RUBRIC);            
             doc['gptRubric']= res;
             return res
         } catch (err) {
@@ -326,8 +306,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
                     break
             }
 
-
-            // const res = await gptAPICall(this.sortDesc, GPTCallType.SUBSET, this.chatSortPrompt);
             // Trigger the callback with the result
             if (this.onSortComplete) {
                 this.onSortComplete(res || 'Something went wrong :(', questionNumber, questionType.split(' ').slice(1).join(' '));
@@ -356,44 +334,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
         this.setSortDone(true);
     };
 
-
-    // /**
-    //  * Sorts cards in the CollectionCardDeckView
-    //  */
-    // generateSort = async () => {
-    //     console.log(this.chatSortPrompt + "USER PROMPT")
-    //     this.setLoading(true);
-    //     this.setSortDone(false);
-
-    //     if (this.regenerateCallback) {
-    //         await this.regenerateCallback();
-    //     }
-    
-    //     try {
-    //         const res = await gptAPICall(this.sortDesc, GPTCallType.SORT, this.chatSortPrompt);
-
-    //         // Trigger the callback with the result
-    //         if (this.onSortComplete) {
-    //             this.onSortComplete(res || 'Something went wrong :(');
-    
-    //             // Extract explanation surrounded by ------ at the top or both at the top and bottom
-    //             const explanationMatch = res.match(/------\s*([\s\S]*?)\s*(?:------|$)/) || [];
-    //             const explanation = explanationMatch[1] ? explanationMatch[1].trim() : 'No explanation found';
-    
-    //             // Set the extracted explanation to sortRespText
-    //             this.setSortRespText(explanation);
-    
-    //             console.log(res);
-    //         }
-    //     } catch (err) {
-    //         console.error(err);
-    //     }
-    
-    //     this.setLoading(false);
-    //     this.setSortDone(true);
-    // };
-    
-    
     /**
      * Generates a Dalle image and uploads it to the server.
      */
@@ -656,6 +596,7 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
                             <input
                                 className="searchBox-input"
                                 defaultValue=""
+                                value={isSort ? this.chatSortPrompt : this.quizAnswer} // Controlled input
                                 autoComplete="off"
                                 onChange={isSort ? this.sortPromptChanged : this.quizAnswerChanged}
                                 onKeyDown={(e) => {
-- 
cgit v1.2.3-70-g09d2

