From df7532553db3df270fcbd25a46e7a349a82bd712 Mon Sep 17 00:00:00 2001 From: aidahosa1 Date: Thu, 16 May 2024 12:52:14 -0400 Subject: pdfs being weird --- .../views/collections/CollectionCardDeckView.tsx | 70 ++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 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 7af6eb614..561b9f806 100644 --- a/src/client/views/collections/CollectionCardDeckView.tsx +++ b/src/client/views/collections/CollectionCardDeckView.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import { Utils, returnFalse, returnTrue, returnZero } from '../../../Utils'; import { Doc, DocListCast, Field, StrListCast } from '../../../fields/Doc'; import { Id } from '../../../fields/FieldSymbols'; -import { NumCast, ScriptCast, StrCast, BoolCast, DocCast, RTFCast } from '../../../fields/Types'; +import { NumCast, ScriptCast, StrCast, BoolCast, DocCast, RTFCast, Cast} from '../../../fields/Types'; import { DragManager } from '../../util/DragManager'; import { SelectionManager } from '../../util/SelectionManager'; import { StyleProp } from '../StyleProvider'; @@ -18,6 +18,9 @@ import { DocumentType } from '../../documents/DocumentTypes'; import { forEach } from 'lodash'; import { SnappingManager } from '../../util/SnappingManager'; import { List } from '../../../fields/List'; +import { gptAPICall } from '../../apis/gpt/GPT'; +import { GPTCallType } from '../../apis/gpt/GPT'; +import { ImageField } from '../../../fields/URLField'; @observer export class CollectionCardView extends CollectionSubView() { @@ -249,6 +252,11 @@ export class CollectionCardView extends CollectionSubView() { // console.log('hiiiii'); return this.sort(sorted, 'custom', desc); + case 'chat': + this.smartSort() + docs = this.myChildLayoutPairs; + return {docs} + default: docs = this.myChildLayoutPairs; return { docs }; @@ -306,7 +314,7 @@ export class CollectionCardView extends CollectionSubView() { // console.log(typeA + "A") typeB = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(docs.indexOf(docB)) ?? '9999'; // console.log(typeB + 'b') - break; + break; default: typeA = docA.layout.type ?? ''; // If docA.type is undefined, use an empty string @@ -468,6 +476,8 @@ export class CollectionCardView extends CollectionSubView() { }); } + + @@ -476,10 +486,62 @@ export class CollectionCardView extends CollectionSubView() { this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].set(childPairIndex, buttonID); this._props.Document.customHashMap = this.mapToField - // const queryText = RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1'])); - // console.log(queryText) + // Cast(selected.Document.data, WebField, null)?.url?.href) + + // StrCast(selected.Document.data, Cast(selected.Document.data, WebField, null)?.url?.href) + + + + // const + const imgurlperchance = Cast(this.childDocs[1].data, ImageField, null)?.url; + + console.log('Print Front of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); + console.log('Print Back of cards: ' + RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); + + + // const queryText = (RTFCast(this.myChildLayoutPairs[0].layout.text)).Text; + // const queryText = RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text; + + console.log(imgurlperchance ?? "sad") } + childPairStringList () { + let string = "" + for (let i=0; i < this.myChildLayoutPairs.length; i++){ + string += StrCast((RTFCast(this.myChildLayoutPairs[i].layout.text)).Text) + ", " + } + return string + } + + @observable isLoading = false + + @action async smartSort() { + this.isLoading = true; + console.log("loading") + let prompt= "" + + if (this.childPairStringList() == ""){ + console.log("no child pairs :(") + } + + else{ + console.log(this.childPairStringList() + "og list") + prompt = "Sort this list of strings by shared content " + this.childPairStringList() + } + + + let res = await gptAPICall(prompt, GPTCallType.SORT); + this.isLoading = false; + if (res == 'Error connecting with API.') { + // If GPT call failed + console.error('GPT call failed'); + } else if (res != null) { + // If GPT call succeeded, set htmlCode;;; TODO: check if valid html + console.log(res) + } + this.isLoading = false; + }; + renderButtons(childPairIndex: number) { const buttons = []; // Array to hold the button elements -- cgit v1.2.3-70-g09d2