diff options
author | aidahosa1 <aisosa_idahosa@brown.edu> | 2024-05-18 01:33:27 -0400 |
---|---|---|
committer | aidahosa1 <aisosa_idahosa@brown.edu> | 2024-05-18 01:33:27 -0400 |
commit | e168e0e880db808589d4c0a85e37c30b177bdb8e (patch) | |
tree | 7a97471b793e586842f20d7783123319fb79ef4e /src | |
parent | 0b32642fc9c2d33810252cd90e45b8b505ef49b2 (diff) |
comments lock in
Diffstat (limited to 'src')
-rw-r--r-- | src/Utils.ts | 1 | ||||
-rw-r--r-- | src/client/views/collections/CollectionCardDeckView.tsx | 323 | ||||
-rw-r--r-- | src/client/views/pdf/GPTPopup/GPTPopup.tsx | 17 |
3 files changed, 119 insertions, 222 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index 291d7c799..fb72a5836 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -179,6 +179,7 @@ export namespace Utils { export function toRGBAstr(col: { r: number; g: number; b: number; a?: number }) { return 'rgba(' + col.r + ',' + col.g + ',' + col.b + (col.a !== undefined ? ',' + col.a : '') + ')'; } + export function HSLtoRGB(h: number, s: number, l: number) { // Must be fractions of 1 diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx index c719c9e19..8a63fc6d9 100644 --- a/src/client/views/collections/CollectionCardDeckView.tsx +++ b/src/client/views/collections/CollectionCardDeckView.tsx @@ -25,30 +25,23 @@ import { GPTPopup } from '../pdf/GPTPopup/GPTPopup'; import { GPTPopupMode } from '../pdf/GPTPopup/GPTPopup'; import { reaction } from 'mobx'; import { NumListCast } from '../../../fields/Doc'; +import { undoBatch } from '../../util/UndoManager'; @observer export class CollectionCardView extends CollectionSubView() { - //TODO: for saving custom groups instead of string field hashmap nonsense should instead just set teh index for each child document per group as a fie;d - // so like, group1Ibndex = 1 etc etc as they change. That way, if the documents change it doesnt matter since the idnexes are tied to the - // documents themselves - @observable hoveredNodeIndex = -1; //key is the index in the child pair list, value is the id# for the group its in @observable customGroupDictionary: Map<number, number>[] = [new Map<number, number>(), new Map<number, number>(), new Map<number, number>()]; - + /** + * The child documents to be rendered-- either all of them except the Links or the docs in the currently active + * custom group + */ @computed get myChildLayoutPairs() { let activeGroups = NumListCast(this._props.Document.visibleGroupNumbers); let currCustom = NumCast(this._props.Document.customSortNumber); - // console.log("Active Groups:", activeGroups); - - // for (let i=0; i< activeGroups.length; i++){ - // console.log("Active Groups" + activeGroups[i]) - // } - // console.log("Current Custom Sort Number:", currCustom); - if (activeGroups.length <= 0) { return this.childLayoutPairs.filter(l => l.layout.type != DocumentType.LINK); } @@ -58,12 +51,8 @@ export class CollectionCardView extends CollectionSubView() { if (l.layout.type === DocumentType.LINK) { return false; } - // Get the group number for the current index from the customGroupDictionary const groupNumber = this.customGroupDictionary[currCustom].get(index); - - // console.log(`Index: ${index}, Group Number: ${groupNumber}`); - // Check if the group number is in the active groups return groupNumber !== undefined && activeGroups.includes(groupNumber); }); @@ -73,13 +62,18 @@ export class CollectionCardView extends CollectionSubView() { return this.childLayoutPairs.filter(l => l.layout.type != DocumentType.LINK); } + @action setHoveredNodeIndex = (index: number) => { if (!this.isSelected(index)) { this.hoveredNodeIndex = index; } }; - + /** + * Translates the hovered node to the center of the screen + * @param index + * @returns + */ translateHover = (index: number): number => { if (this.hoveredNodeIndex == index && !this.isSelected(index)) { return -50; @@ -90,30 +84,22 @@ export class CollectionCardView extends CollectionSubView() { @action setSelectedNodeIndex = (index: number) => { const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]); - // console.log('goodnight'); - if (SelectionManager.IsSelected(docs[index])) { - // console.log('good mornings'); this.setSelectedNodeIndex(index); } - - - }; isSelected = (index: number): boolean => { const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]); - return SelectionManager.IsSelected(docs[index]); }; + /** + * Returns all the documents except the one that's currently selected + */ inactiveDocs = () => { - const docs = this.myChildLayoutPairs; - - - return docs.filter(d => !SelectionManager.IsSelected(d.layout)); - - + const docs = this.myChildLayoutPairs; + return docs.filter(d => !SelectionManager.IsSelected(d.layout)); }; middleIndex = Math.floor(this.inactiveDocs().length / 2); @@ -121,10 +107,9 @@ export class CollectionCardView extends CollectionSubView() { constructor(props: any) { super(props); makeObservable(this); - // this.rotationDegree(7); const pairs = this.childLayoutPairs.filter(d => d.layout.type != DocumentType.LINK); - + //gets the values from the last time the view was loaded and puts them into their respective places in the hashmaps(s) for (let i=0; i< pairs.length; i++){ if (pairs[i].layout.custom1Group != undefined){ this.customGroupDictionary[0].set(i, NumCast(pairs[i].layout.custom1Group)) @@ -144,14 +129,6 @@ export class CollectionCardView extends CollectionSubView() { } } - - // if (this._props.Document.customHashMap != undefined){ - // this.customGroupDictionary = this.convertListsToArrayOfMaps(DocListCast(this._props.Document.customGroup1),DocListCast(this._props.Document.customGroup2), DocListCast(this._props.Document.customGroup3)) - // } - // this._props.Document.visibleGroupNumbers = new List<number>([1,2,3,4]) - - - reaction( () => this._props.Document.cardSort, (cardSort) => { @@ -162,60 +139,6 @@ export class CollectionCardView extends CollectionSubView() { ); } - //converts the customGroupDictionary into a Lists of Docs - mapToField(groupNumber: number) { - const groupList = new List<Doc>(); - - const pairs = this.childLayoutPairs.filter(d => d.layout.type != DocumentType.LINK); - console.log(groupNumber+ "group#") - - this.customGroupDictionary[groupNumber].forEach((group, index) => { - const doc = pairs[index].layout; - groupList.push(doc); - }); - - this._props.Document[`group${groupNumber}`] = groupList; - } - - // This function converts three Lists of Docs back into an array of maps - convertListsToArrayOfMaps = (group0: Doc[], group1: Doc[], group2: Doc[]): Map<number, number>[] => { - const mapsArray: Map<number, number>[] = [ - new Map<number, number>(), - new Map<number, number>(), - new Map<number, number>() - ]; - const layoutPairs = this.childLayoutPairs.filter(d => d.layout.type != DocumentType.LINK) - - group0.forEach((doc, index) => { - const docIndex = layoutPairs.findIndex(pair => pair.layout === doc); - if (docIndex !== -1) { - mapsArray[0].set(docIndex, 0); - } - }); - - group1.forEach((doc, index) => { - const docIndex = layoutPairs.findIndex(pair => pair.layout === doc); - if (docIndex !== -1) { - mapsArray[1].set(docIndex, 1); - } - }); - - group2.forEach((doc, index) => { - const docIndex = layoutPairs.findIndex(pair => pair.layout === doc); - if (docIndex !== -1) { - mapsArray[2].set(docIndex, 2); - } - }); - - return mapsArray; - } - - - - - - - private _dropDisposer?: DragManager.DragDropDisposer; componentWillUnmount() { @@ -241,31 +164,34 @@ export class CollectionCardView extends CollectionSubView() { } return (this.childDocumentWidth * length) / this._props.PanelWidth(); } + panelWidth = () => this.childDocumentWidth; panelHeight = (layout: Doc) => () => (2 * (this.panelWidth() * NumCast(layout._height))) / NumCast(layout._width); onChildDoubleClick = () => ScriptCast(this.layoutDoc.onChildDoubleClick); isContentActive = () => this._props.isSelected() || this._props.isContentActive() || this._props.isAnyChildContentActive(); isChildContentActive = () => (this.isContentActive() ? true : false); + /** + * Returns the degree to rotate a card dependind on the amount of cards in their row and their index in said row + * @param amCards + * @param index + * @returns + */ rotate = (amCards: number, index: number) => { - // console.log(amCards + "wtf") const possRotate = -30 + index * (30 / ((amCards - (amCards % 2)) / 2)); const stepMag = Math.abs(-30 + (amCards / 2 - 1) * (30 / ((amCards - (amCards % 2)) / 2))); - // console.log(possRotate + "poss") - if (amCards % 2 == 0 && possRotate == 0) { - // console.log('whaddup'); return possRotate + Math.abs(-30 + (index - 1) * (30 / (amCards / 2))); } else if (amCards % 2 == 0 && index > (amCards + 1) / 2) { - // console.log("sup" + stepMag); - return possRotate + stepMag; } return possRotate; }; - + /** + * Returns the degree to which a card should be translated in the y direction for the arch effect + */ translateY = (amCards: number, index: number, realIndex: number) => { const evenOdd = amCards % 2; const apex = (amCards - evenOdd) / 2; @@ -273,14 +199,9 @@ export class CollectionCardView extends CollectionSubView() { let rowOffset = 0; if (realIndex > this.maxRowCount - 1) { - // 11 - 1 = 10 rowOffset = 400 * ((realIndex - (realIndex % this.maxRowCount)) / this.maxRowCount); } - - // console.log('steo' + stepMag); - if (evenOdd == 1 || index < apex - 1) { - // console.log('hi' + index); return Math.abs(stepMag * (apex - index)) - rowOffset; } else { if (index == apex || index == apex - 1) { @@ -291,13 +212,11 @@ export class CollectionCardView extends CollectionSubView() { } }; - // translateOverFlowY = (amCards: number, index: number) => { - // if (amCards > 8 && index > amCards / 2) { - // return 100; - // } - // return 0; - // }; - + /** + * Translates the selected node to the middle fo the screen + * @param index + * @returns + */ translateSelected = (index: number): number => { // if (this.isSelected(index)) { const middleOfPanel = this._props.PanelWidth() / 2; @@ -312,17 +231,12 @@ export class CollectionCardView extends CollectionSubView() { const translation = middleOfPanel - scaledNodeCenter - scaledNodeWidth - scaledNodeWidth / 4; return translation; - // } - - // return 0; }; - @observable sortedDocs = [] as { layout: Doc; data: Doc }[]; - - + /** + * Determines the order in which the cards will be rendered depending on the current sort type + */ @computed get sortedDocsType() { - - const desc = BoolCast(this.layoutDoc.sortDesc); let sorted = []; let docs = []; @@ -348,7 +262,11 @@ export class CollectionCardView extends CollectionSubView() { return { docs }; } } - + /** + * Converts a hex # to its hsv color value + * @param hex + * @returns + */ hexToHsv = (hex: string): [number, number, number] => { if (!hex) return [0, 0, 0]; // Default to black if hex is not defined const r = parseInt(hex.slice(1, 3), 16) / 255; @@ -381,7 +299,14 @@ export class CollectionCardView extends CollectionSubView() { h /= 6; return [h, s, v]; }; - + /** + * Called in the sortedDocsType method. Compares the cards' value in regards to the desired sort type-- earlier cards are move to the + * front, latter cards to the back + * @param docs + * @param sortType + * @param isDesc + * @returns + */ sort = (docs: { layout: Doc; data: Doc }[], sortType: string, isDesc: boolean) => { docs.sort((docA, docB) => { let typeA; @@ -394,26 +319,13 @@ export class CollectionCardView extends CollectionSubView() { break; case 'custom': - - // console.log(this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)]) typeA = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(docs.indexOf(docA)) ?? '9999'; - // console.log(typeA + "A") typeB = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(docs.indexOf(docB)) ?? '9999'; - // console.log(typeB + 'b') break; case 'gpt': - - // console.log(this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)]) typeA = this.gptGroups.get(docA.layout) ?? '9999'; - // console.log(typeA + "typea") typeB = this.gptGroups.get(docB.layout) ?? '9999'; - // console.log(typeB + "typeB") - - - // console.log(typeA + "A") - // typeB = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(docs.indexOf(docB)) ?? '9999'; - // console.log(typeB + 'b') break; default: @@ -433,9 +345,6 @@ export class CollectionCardView extends CollectionSubView() { return { docs }; }; - // @computed get cards(){ - - // } displayDoc = (childPair: { layout: Doc; data: Doc }, screenToLocalTransform: () => Transform) => { return ( @@ -444,8 +353,6 @@ export class CollectionCardView extends CollectionSubView() { ref={action((r: DocumentView) => r?.ContentDiv && this.docRefs.set(childPair.layout, r))} Document={childPair.layout} TemplateDataDocument={childPair.data} - // onClickScript={this.toggleIcon} - //suppressSetHeight={true} NativeWidth={returnZero} NativeHeight={returnZero} layout_fitWidth={returnFalse} @@ -453,7 +360,6 @@ export class CollectionCardView extends CollectionSubView() { renderDepth={this._props.renderDepth + 1} LayoutTemplate={this._props.childLayoutTemplate} LayoutTemplateString={this._props.childLayoutString} - // focus={this.focus} ScreenToLocalTransform={screenToLocalTransform} //makes sure the box wrapper thing is in the right spot isContentActive={this.isChildContentActive} isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive} @@ -467,6 +373,11 @@ export class CollectionCardView extends CollectionSubView() { @observable maxRowCount = 10; + /** + * Determines how many cards are in the row of a card at a specific index + * @param index + * @returns + */ overflowAmCardsCalc(index: number) { if (this.inactiveDocs().length < this.maxRowCount) { return this.inactiveDocs().length; @@ -480,7 +391,11 @@ export class CollectionCardView extends CollectionSubView() { //(3) return totalCards % 10; } - + /** + * Determines the index a card is in in a row + * @param realIndex + * @returns + */ overflowIndexCalc(realIndex: number) { if (realIndex < 10) { return realIndex; @@ -488,21 +403,29 @@ export class CollectionCardView extends CollectionSubView() { return realIndex % 10; } - + /** + * Translates the cards in the second rows and beyond over to the right + * @param realIndex + * @param calcIndex + * @param calcRowCards + * @returns + */ translateOverflowX(realIndex: number, calcIndex: number, calcRowCards: number) { - - let trans = 0; - - // trans += (calcIndex * this.panelWidth()) + this.panelWidth() - - // return trans if (realIndex < this.maxRowCount) { return 0; } return (10 - calcRowCards) * (this.panelWidth() / 2); } - + /** + * Determines how far to translate a card in the y direction depending on its index, whether or not its being hovered, or if it's selected + * @param isHovered + * @param isSelected + * @param realIndex + * @param amCards + * @param calcRowIndex + * @returns + */ calculateTranslateY(isHovered: boolean, isSelected: boolean, realIndex: number, amCards: number, calcRowIndex: number) { let trans = 0; if (isHovered) { @@ -510,25 +433,23 @@ export class CollectionCardView extends CollectionSubView() { } trans += this.translateY(amCards, calcRowIndex, realIndex); - if (isSelected) { trans = 50 * this.fitContentScale; } - return trans; } @observable _forceChildXf = false; + + /** + * Actually renders all the cards + */ @computed get contentSorted() { const sortedDocs = this.sortedDocsType.docs; - // const amCards = this.inactiveDocs().length; - // Map sorted documents to their rendered components return sortedDocs.map((childPair, index) => { - // const childPair = { layout: doc, data: doc }; const isHovered = this.hoveredNodeIndex === index; - // const childPairIndex = this.myChildLayoutPairs.indexOf(childPair); const childPairIndex = this.childLayoutPairs.filter(d => d.layout.type != DocumentType.LINK).indexOf(childPair) const realIndex = this.sortedDocsType.docs.filter(d => !SelectionManager.IsSelected(d.layout)).indexOf(childPair); const calcRowIndex = this.overflowIndexCalc(realIndex); @@ -578,8 +499,16 @@ export class CollectionCardView extends CollectionSubView() { ); }); } - + /** + * Toggles the buttons between on and off when creating custom sort groupings/changing those created by gpt + * @param childPairIndex + * @param buttonID + * @param isChat + * @param doc + */ + + @undoBatch @action toggleButton(childPairIndex: number, buttonID: number, isChat = false, doc: Doc) { if (!isChat) { const sortNumber = NumCast(this._props.Document.customSortNumber) @@ -597,22 +526,20 @@ export class CollectionCardView extends CollectionSubView() { default: break } - // this.mapToField(buttonID); } if (isChat && doc) { this.gptGroups.set(doc, buttonID); doc.chatGroup = buttonID } - - // console.log(`Toggled button for childPairIndex: ${childPairIndex}, buttonID: ${buttonID}, isChat: ${isChat}`); - // console.log(`Updated customGroupDictionary:`, this.customGroupDictionary); - // if (isChat && doc) { - // // console.log(`Updated gptGroups for doc ${doc}:`, this.gptGroups.get(doc)); - // } } - + /** + * A list of the text content of all the child docs. RTF documents will have just their text and pdf documents will have the first 50 words. + * Image documents are converted to bse64 and gpt generates a description for them. all other documents use their title. This string is + * inputted into the gpt prompt to sort everything together + * @returns + */ async childPairStringList(): Promise<string> { let string = ""; for (let i = 0; i < this.childDocs.length; i++) { @@ -645,7 +572,8 @@ export class CollectionCardView extends CollectionSubView() { } @observable isLoading = false - + + imageUrlToBase64 = async (imageUrl: string): Promise<string> => { try { const response = await fetch(imageUrl); @@ -666,6 +594,11 @@ export class CollectionCardView extends CollectionSubView() { textToDoc = new Map<string, Doc>() gptProccessedImages = new Set<Doc>() + /** + * Calls the gpt API to generate descriptions for the images in the view + * @param image + * @returns + */ @action async getImageDesc(image: Doc) { if (this.gptProccessedImages.has(image)) { // Return the already processed description @@ -687,11 +620,14 @@ export class CollectionCardView extends CollectionSubView() { } } - + //child doc to its group determind by gpt gptGroups = new ObservableMap<Doc, number> @observable amGPTGroups = 0 - - // Method to convert the GPT-produced string into a map + + /** + * Converts the gpt output into a hashmap that can be used for sorting. lists are seperated by ==== while elements within the list are seperated by ~~~~~~ + * @param gptOutput + */ processGptOutput(gptOutput: string) { // Split the string into individual list items @@ -708,9 +644,7 @@ export class CollectionCardView extends CollectionSubView() { // Find the corresponding Doc in the textToDoc map if (this.textToDoc.has(part)) { const doc = this.textToDoc.get(part); - console.log("hewoooooo") if (doc) { - console.log('hi') this.gptGroups.set(doc, index); } } @@ -719,7 +653,9 @@ export class CollectionCardView extends CollectionSubView() { } @observable isChatPopupOpen = false; - + /** + * Opens up the chat popup and starts the process for smart sorting. + */ @action openChatPopup = async () => { this.isChatPopupOpen = true; GPTPopup.Instance.setVisible(true); @@ -733,18 +669,20 @@ export class CollectionCardView extends CollectionSubView() { }; @action handleGptSortResult = (sortResult: string) => { this.processGptOutput(sortResult); - this.sortedDocs = this.sort(this.myChildLayoutPairs, 'gpt', BoolCast(this.layoutDoc.sortDesc)).docs; }; - - - - + /** + * Renders the buttons to customize sorting depending on which group the card belongs to and the amount of total groups + * @param childPairIndex + * @param doc + * @param isChat + * @returns + */ renderButtons(childPairIndex: number, doc: Doc, isChat = false) { - const buttons = []; // Array to hold the button elements + const buttons = []; const groupNumber = NumCast(this._props.Document.customSortNumber); - let amButtons = 4; // Adjusted to your context + let amButtons = 4; let activeButtonIndex = this.customGroupDictionary[groupNumber].get(childPairIndex); if (isChat && doc) { @@ -754,11 +692,8 @@ export class CollectionCardView extends CollectionSubView() { activeButtonIndex = this.gptGroups.get(doc); } - // console.log("childPairIndex:", childPairIndex, "activeButtonIndex:", activeButtonIndex, "groupNumber:", groupNumber); - for (let i = 0; i < amButtons; i++) { const isActive = activeButtonIndex === i; - // console.log(`Rendering button ${i} for childPairIndex ${childPairIndex} isActive: ${isActive}`); buttons.push( <button key={i} @@ -783,30 +718,8 @@ export class CollectionCardView extends CollectionSubView() { if (this.inactiveDocs().length != this.myChildLayoutPairs.length && this.inactiveDocs().length < 10) { translate += this.panelWidth() / 2; } - - // console.log('in' + this.inactiveDocs().length); - // console.log('max' + this.maxRowCount); - - // if (this.inactiveDocs().length > this.maxRowCount){ - // translate += ((this.inactiveDocs().length % this.maxRowCount) * this.panelWidth()) / 2 - // console.log("trans" + (this.inactiveDocs().length % this.maxRowCount) / 2 ) - // } - return translate; } - - // @computed get renderCardsSort(){ - // if (StrCast(this._props.Document.cardSort) == "type"){ - // return this.contentSorted - // } - - // else{ - // return this.content - // } - // } - - - render() { return ( <div diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index d94be1860..3d138fa7d 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -133,20 +133,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> { }; @observable - public sortPrompt: string = ''; - @action - public setSortPrompt = ((e: React.ChangeEvent<HTMLInputElement>) => { - this.sortPrompt = e.target.value; - }); - - @observable - public sortText: string = '' - @action - public setSortText = (t: string) => { - this.sortText = t - } - - @observable public sortDesc: string = '' @action public setSortDesc = (t:string) => { @@ -178,8 +164,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> { try { const res = await gptAPICall(this.sortDesc, GPTCallType.SORT); - this.setSortText(res || 'Something went wrong :('); - // Trigger the callback with the result if (this.onSortComplete) { this.onSortComplete(res || 'Something went wrong :('); @@ -187,7 +171,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> { } } catch (err) { console.error(err); - this.setSortText('Something went wrong :('); } this.setLoading(false); |