From 8ca77556c3a9caba66faf37fbf259762c2084c0b Mon Sep 17 00:00:00 2001
From: aidahosa1 <aisosa_idahosa@brown.edu>
Date: Tue, 7 May 2024 17:28:21 -0400
Subject: hm

---
 .../views/collections/CollectionCardDeckView.tsx   | 42 ++++++++++++++++------
 1 file changed, 32 insertions(+), 10 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 d0a796218..ab7aac267 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -159,14 +159,18 @@ export class CollectionCardView extends CollectionSubView() {
     };
 
     @computed get sortedDocsType() {
-        // This field is set to 'type' to sort documents by their type
-        // const typeField = 'type';
-
-        // Whether to sort in descending order
+        
         const desc = BoolCast(this.layoutDoc.sortDesc);
 
+        let sorted = []
+
+        for (let i=0; i< this.childLayoutPairs.length; i++){ //copying everything in childlayout pairs to sorted so that i can use the sort function without altering the original list
+            sorted[i] = this.childLayoutPairs[i]
+        }
+
+
         // Copy and sort documents by type
-        const docs = this.childLayoutPairs.sort((docA, docB) => {
+        const docs = sorted.sort((docA, docB) => {
             const typeA = docA.layout.type ?? ''; // If docA.type is undefined, use an empty string
             const typeB = docB.layout.type ?? ''; // If docB.type is undefined, use an empty string
 
@@ -177,10 +181,15 @@ export class CollectionCardView extends CollectionSubView() {
             if (desc) out *= -1; // Reverse the sort order if descending is true
             return out;
         });
+        
 
         return { docs };
     }
 
+    
+
+   
+
     @observable docRefs = new ObservableMap<Doc, DocumentView>();
 
     @computed get contentSorted() {
@@ -213,9 +222,10 @@ export class CollectionCardView extends CollectionSubView() {
         // Map sorted documents to their rendered components
         return sortedDocs.map((childPair, index) => {
             // const childPair = { layout: doc, data: doc }; 
-            const isSelected = this.isSelected(index);
             const isHovered = this.hoveredNodeIndex === index;
-            const inactiveIndex = this.sortedDocsType.docs.indexOf(childPair);
+            const inactiveIndex = this.sortedDocsType.docs.filter(d => !SelectionManager.IsSelected(d.layout)).indexOf(childPair);
+            const isSelected = SelectionManager.IsSelected(childPair.layout);
+
 
 
 
@@ -234,7 +244,7 @@ export class CollectionCardView extends CollectionSubView() {
                         height: this.panelHeight(childPair.layout)(),
                         transform: `
                             rotate(${!isSelected ? this.rotate(amCards, inactiveIndex) : 0}deg)
-                            translateY(${isHovered ? this.translateHover(index) : isSelected ? 50 * this.fitContentScale : this.translateY(amCards, inactiveIndex)}px)
+                            translateY(${isHovered ? this.translateHover(inactiveIndex) : isSelected ? 50 * this.fitContentScale : this.translateY(amCards, inactiveIndex)}px)
                             translateX(${isSelected ? (this._props.PanelWidth() / 2) * this.fitContentScale - this.childDocumentWidth : 0}px)
                             scale(${isSelected ? 1.25 : 1})
                         `,
@@ -250,7 +260,7 @@ export class CollectionCardView extends CollectionSubView() {
         // const currentIndex = NumCast(this.layoutDoc._carousel_index);
         const amCards = this.inactiveDocs().length;
         console.log(amCards + "lol")
-        const sortedDocs = this.sortedDocsType.docs; // Retrieve sorted documents
+        // const sortedDocs = this.sortedDocsType.docs; // Retrieve sorted documents
 
         // const myInactives =
         const displayDoc = (childPair: { layout: Doc; data: Doc }, screenToLocalTransform: () => Transform) => {
@@ -328,6 +338,18 @@ export class CollectionCardView extends CollectionSubView() {
         return 0;
     }
 
+    @computed get renderCardsSort(){
+        if (BoolCast(this._props.Document.card_sort_type) == true){
+            return this.contentSorted
+        }
+
+        else{
+            return this.content
+        }
+    }
+
+    
+
     render() {
         return (
             <div
@@ -345,7 +367,7 @@ export class CollectionCardView extends CollectionSubView() {
                         height: `${100 * this.fitContentScale}%`,
                     }}
                     onMouseLeave={() => this.setHoveredNodeIndex(-1)}>
-                    {this.contentSorted}
+                    {this.renderCardsSort}
                 </div>
 
                 {/* <Card  className={`custom-modal-position step-${step}`}>
-- 
cgit v1.2.3-70-g09d2

