From 313b3d3e67689b175cdc85426ff6af809d476622 Mon Sep 17 00:00:00 2001
From: aidahosa1 <aisosa_idahosa@brown.edu>
Date: Tue, 17 Sep 2024 12:55:38 -0400
Subject: done with comments-- pull request

---
 .../views/collections/CollectionCardDeckView.tsx   | 41 +++++++++++++---------
 1 file changed, 25 insertions(+), 16 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 2390d162c..3d9f28a49 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -23,6 +23,8 @@ import { dropActionType } from '../../util/DropActionTypes';
 import { DocCast } from '../../../fields/Types';
 import { SelectionManager } from '../../util/SelectionManager';
 
+
+
 enum cardSortings {
     Time = 'time',
     Type = 'type',
@@ -32,6 +34,14 @@ enum cardSortings {
     Tag = 'tag',
     None = '',
 }
+
+/**
+ * New view type specifically for studying more dynamically. Allows you to reorder docs however you see fit, easily 
+ * sort and filter using presets, and customize your experience with chat gpt.
+ * 
+ * This file contains code as to how the docs are to be rendered (there place geographically and also in regards to sorting),
+ * and callback functions for the gpt popup
+ */
 @observer
 export class CollectionCardView extends CollectionSubView() {
     private _dropDisposer?: DragManager.DragDropDisposer;
@@ -40,10 +50,8 @@ export class CollectionCardView extends CollectionSubView() {
     private _textToDoc = new Map<string, Doc>();
 
     @observable _forceChildXf = false;
-    // @observable _isLoading = false;
     @observable _hoveredNodeIndex = -1;
     @observable _docRefs = new ObservableMap<Doc, DocumentView>();
-    _draggerRef = React.createRef<HTMLDivElement>();
     @observable _maxRowCount = 10;
     @observable _docDraggedIndex: number = -1;
     @observable _isACardBeingDragged: boolean = false;
@@ -99,12 +107,12 @@ export class CollectionCardView extends CollectionSubView() {
 
         // Reaction to cardSort changes
         this._disposers.sort = reaction(
-            () => this.cardSort,
-            cardSort => {
-                if (cardSort === cardSortings.Chat) {
+            () => GPTPopup.Instance.visible,
+            isVis => {
+                if (isVis) {
                     this.openChatPopup();
                 } else {
-                    GPTPopup.Instance.setVisible(false);
+                    this.Document.cardSort = (this.cardSort === cardSortings.Chat) ? '' : this.Document.cardSort;
                 }
             }
         );
@@ -296,7 +304,7 @@ export class CollectionCardView extends CollectionSubView() {
      * @param de drop event
      * @returns true if a card has been dropped, falls if not
      */
-    onInternalDrop = (e: Event, de: DragManager.DropEvent) => {
+    onInternalDrop = undoable((e: Event, de: DragManager.DropEvent) => {
         if (de.complete.docDragData) {
             this._isACardBeingDragged = false;
             this._docDraggedIndex = -1;
@@ -304,7 +312,7 @@ export class CollectionCardView extends CollectionSubView() {
             return true;
         }
         return false;
-    };
+    }, '' );
 
     get sortedDocs() {
         return this.sort(this.childDocsWithoutLinks, this.cardSort, BoolCast(this.Document.cardSort_isDesc), this._docDraggedIndex);
@@ -511,8 +519,6 @@ export class CollectionCardView extends CollectionSubView() {
             image[DocData].description = response.trim();
             return response; // Return the response from gptImageLabel
         } catch (error) {
-            console.log('bad things have happened');
-
             console.log(error);
         }
         return '';
@@ -523,18 +529,22 @@ export class CollectionCardView extends CollectionSubView() {
      * usable code
      * @param gptOutput
      */
-    @action processGptOutput = (gptOutput: string, questionType: string, tag?: string) => {
-        console.log('HIIII');
-        console.log(StrCast(this.Document.cardSort) + 'cardSort');
+    @action 
+    
+    processGptOutput = undoable((gptOutput: string, questionType: string, tag?: string) => {
         // Split the string into individual list items
         const listItems = gptOutput.split('======').filter(item => item.trim() !== '');
 
-        if (questionType == '2' || questionType == '4') {
+        if (questionType === '2' || questionType === '4') {
             this.childDocs.forEach(d => {
                 d['chatFilter'] = false;
             });
         }
 
+        if (questionType ==='6'){
+            this.Document.cardSort = 'chat'
+        }
+
 
         listItems.forEach((item, index) => {
             const normalizedItem = item.trim();
@@ -545,7 +555,6 @@ export class CollectionCardView extends CollectionSubView() {
                 switch (questionType) {
                     case '6':
                         doc.chatIndex = index;
-                        console.log(index);
                         break;
                     case '1':
                         const allHotKeys = StrListCast(Doc.UserDoc().myFilterHotKeyTitles);
@@ -578,7 +587,7 @@ export class CollectionCardView extends CollectionSubView() {
                 console.warn(`No matching document found for item: ${normalizedItem}`);
             }
         });
-    };
+    }, '');
 
 
     /**
-- 
cgit v1.2.3-70-g09d2

