From 10ae244338383662992350b2b6f6ef80106558c3 Mon Sep 17 00:00:00 2001
From: aidahosa1 <aisosa_idahosa@brown.edu>
Date: Fri, 17 May 2024 14:28:09 -0400
Subject: yay git add -A

---
 .../views/collections/CollectionCardDeckView.tsx   | 52 +++++++++++++++++++---
 1 file changed, 46 insertions(+), 6 deletions(-)

(limited to 'src/client/views/collections/CollectionCardDeckView.tsx')

diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx
index e64c013f1..e96fbc161 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -21,7 +21,9 @@ import { List } from '../../../fields/List';
 import { gptAPICall, gptImageLabel } from '../../apis/gpt/GPT';
 import { GPTCallType } from '../../apis/gpt/GPT';
 import { ImageField, PdfField, URLField } from '../../../fields/URLField';
-
+import { GPTPopup } from '../pdf/GPTPopup/GPTPopup';
+import { GPTPopupMode } from '../pdf/GPTPopup/GPTPopup';
+import { reaction } from 'mobx';
 @observer
 export class CollectionCardView extends CollectionSubView() {
 
@@ -88,6 +90,15 @@ export class CollectionCardView extends CollectionSubView() {
         if (this._props.Document.customHashMap != undefined){
             this.customGroupDictionary = this.getCustoms(StrListCast(this._props.Document.customHashMap))
         }
+
+        reaction(
+            () => this._props.Document.cardSort,
+            (cardSort) => {
+                if (cardSort === 'chat') {
+                    this.openChatPopup();
+                }
+            }
+        );
     }
 
     @observable customGroupDictionary: Map<number, number>[] = [new Map<number, number>(), new Map<number, number>(), new Map<number, number>()];
@@ -230,10 +241,18 @@ export class CollectionCardView extends CollectionSubView() {
 
 
     @computed get sortedDocsType() {
-        if (this._props.Document.cardSort === 'chat' && this.sortedDocs.length === 0) {
-            this.smartSort(); // Trigger the sorting if it hasn't been done yet
-            return { docs: [] }; // Return an empty array or a loading state
-        }
+        // if (this._props.Document.cardSort === 'chat'){
+        //     this.openChatPopup()
+        //     const textDesc = await this.childPairStringList();
+        //     GPTPopup.Instance.setSortDesc(textDesc)
+        // }
+
+        // if (this._props.Document.cardSort === 'chat' && this.sortedDocs.length === 0) {
+
+        //     this.smartSort(); // Trigger the sorting if it hasn't been done yet
+        //     return { docs: [] }; // Return an empty array or a loading state
+        // }
+
     
         const desc = BoolCast(this.layoutDoc.sortDesc);
         let sorted = [];
@@ -253,7 +272,7 @@ export class CollectionCardView extends CollectionSubView() {
             case 'custom':
                 return this.sort(sorted, 'custom', desc);
             case 'chat':
-                return { docs: this.sortedDocs }; // Use the sorted docs from the observable
+                return { docs: this.sortedDocs || this.myChildLayoutPairs}; // Use the sorted docs from the observable
             default:
                 docs = this.myChildLayoutPairs;
                 return { docs };
@@ -656,6 +675,25 @@ export class CollectionCardView extends CollectionSubView() {
         });
     }
 
+    @observable isChatPopupOpen = false;
+
+    @action openChatPopup = async () => {
+    this.isChatPopupOpen = true;
+    GPTPopup.Instance.setVisible(true);
+    GPTPopup.Instance.setMode(GPTPopupMode.SORT);
+    
+    // Await the promise to get the string result
+    const sortDesc = await this.childPairStringList();
+    GPTPopup.Instance.setSortDesc(sortDesc);
+    GPTPopup.Instance.onSortComplete = this.handleGptSortResult;
+};
+    @action handleGptSortResult = (sortResult: string) => {
+        this.processGptOutput(sortResult);
+        this.sortedDocs = this.sort(this.myChildLayoutPairs, 'gpt', BoolCast(this.layoutDoc.sortDesc)).docs;
+    };
+
+
+
     
 
     renderButtons(childPairIndex: number) {
@@ -708,6 +746,8 @@ export class CollectionCardView extends CollectionSubView() {
     //     }
     // }
 
+   
+
     render() {
         return (
             <div
-- 
cgit v1.2.3-70-g09d2

