From 1e673454f8cabf894e8dfec36734d2cb41caa7b1 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 3 Feb 2025 10:23:56 -0500
Subject: changed filter 'check' to be exact match and 'match' to be substring.
  fixed GPTpopup filtering to use a #chat tag instead of a chatFilter field.

---
 src/client/views/pdf/GPTPopup/GPTPopup.tsx | 57 +++++++++++++-----------------
 1 file changed, 25 insertions(+), 32 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 da0cbea7a..f5a9f9e6a 100644
--- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx
+++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
@@ -46,9 +46,9 @@ export class GPTPopup extends ObservableReactComponent<object> {
     @observable private chatMode: boolean = false;
     private correlatedColumns: string[] = [];
 
-    @observable public visible: boolean = false;
+    @observable public Visible: boolean = false;
     @action public setVisible = (vis: boolean) => {
-        this.visible = vis;
+        this.Visible = vis;
     };
     @observable public loading: boolean = false;
     @action public setLoading = (loading: boolean) => {
@@ -114,8 +114,8 @@ export class GPTPopup extends ObservableReactComponent<object> {
         this.sortDesc = t;
     };
 
-    @observable onSortComplete?: (sortResult: string, questionType: string, tag?: string) => void;
-    @observable onQuizRandom?: () => void;
+    onSortComplete?: (sortResult: string, questionType: string, tag?: string) => void;
+    onQuizRandom?: () => void;
     @observable cardsDoneLoading = false;
 
     @observable collectionDoc: Doc | undefined = undefined;
@@ -154,30 +154,27 @@ export class GPTPopup extends ObservableReactComponent<object> {
     generateQuiz = async () => {
         this.setLoading(true);
 
-        const selected = DocumentView.SelectedDocs().lastElement();
+        await this.regenerateCallback?.();
 
-        const questionText = 'Question: ' + StrCast(selected.gptInputText);
-        const rubricText = 'Rubric: ' + StrCast(selected.gptRubric);
-        const queryText = questionText + ' UserAnswer: ' + this.quizAnswer + '. ' + rubricText;
+        const selected = DocumentView.SelectedDocs().lastElement();
+        if (!StrCast(selected.gptRubric)) {
+            await this.generateRubric(StrCast(selected.gptInputText), selected);
+        }
 
         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);
+            const res = await gptAPICall('Question: ' + StrCast(selected.gptInputText) + ' UserAnswer: ' + this.quizAnswer + '.  Rubric: ' + StrCast(selected.gptRubric), GPTCallType.QUIZ);
+            if (res) {
+                this.setQuizResp(res);
+                this.conversationArray.push(res);
 
-            this.setLoading(false);
+                this.setLoading(false);
+                this.onQuizRandom?.();
+            } else {
+                console.error('GPT provided no response');
+            }
         } catch (err) {
             console.error('GPT call failed', err);
         }
-
-        if (this.onQuizRandom) {
-            this.onQuizRandom();
-        }
     };
 
     /**
@@ -223,9 +220,7 @@ export class GPTPopup extends ObservableReactComponent<object> {
     generateCard = async () => {
         this.setLoading(true);
 
-        if (this.regenerateCallback) {
-            await this.regenerateCallback();
-        }
+        await this.regenerateCallback?.();
 
         try {
             const questionType = await gptAPICall(this.chatSortPrompt, GPTCallType.TYPE);
@@ -442,9 +437,7 @@ export class GPTPopup extends ObservableReactComponent<object> {
                 onClick={() => {
                     this.conversationArray = ['Define the selected card!'];
                     this.setMode(GPTPopupMode.QUIZ);
-                    if (this.onQuizRandom) {
-                        this.onQuizRandom();
-                    }
+                    this.onQuizRandom?.();
                 }}
                 color={StrCast(Doc.UserDoc().userVariantColor)}
                 type={Type.TERT}
@@ -694,13 +687,13 @@ export class GPTPopup extends ObservableReactComponent<object> {
                         <IconButton color={StrCast(SettingsManager.userVariantColor)} tooltip="back" icon={<CgCornerUpLeft size="16px" />} onClick={() => (this.mode = GPTPopupMode.CARD)} style={{ right: '50px', position: 'absolute' }} />
                     )}
                     <Toggle
-                        tooltip="clear filters"
+                        tooltip="Clear Chat filter"
                         toggleType={ToggleType.BUTTON}
                         type={Type.PRIM}
-                        toggleStatus={this.collectionDoc?.childFilters ? true : false}
-                        text={this.collectionDoc?.childFilters ? 'filtered' : ''}
+                        toggleStatus={Doc.hasDocFilter(this.collectionDoc, 'tags', '#chat')}
+                        text={Doc.hasDocFilter(this.collectionDoc, 'tags', '#chat') ? 'filtered' : ''}
                         color="red"
-                        onClick={() => this.collectionDoc && (this.collectionDoc.childFilters = undefined)}
+                        onClick={() => this.collectionDoc && Doc.setDocFilter(this.collectionDoc, 'tags', '#chat', 'remove')}
                     />
                     <IconButton
                         color={StrCast(SettingsManager.userVariantColor)}
@@ -738,7 +731,7 @@ export class GPTPopup extends ObservableReactComponent<object> {
         }
 
         return (
-            <div className="summary-box" style={{ display: this.visible ? 'flex' : 'none' }}>
+            <div className="summary-box" style={{ display: this.Visible ? 'flex' : 'none' }}>
                 {content}
                 <div className="resize-handle" />
             </div>
-- 
cgit v1.2.3-70-g09d2

