diff options
| author | aidahosa1 <aisosa_idahosa@brown.edu> | 2024-05-17 14:28:09 -0400 |
|---|---|---|
| committer | aidahosa1 <aisosa_idahosa@brown.edu> | 2024-05-17 14:28:09 -0400 |
| commit | 10ae244338383662992350b2b6f6ef80106558c3 (patch) | |
| tree | 0226d1309399298ea149d42343c90c86ad3301ca /src/client/views/collections | |
| parent | 825463b4f7bb609082d16b302d40c6af56c98b26 (diff) | |
yay git add -A
Diffstat (limited to 'src/client/views/collections')
| -rw-r--r-- | src/client/views/collections/CollectionCardDeckView.tsx | 52 |
1 files changed, 46 insertions, 6 deletions
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 |
