From a64b1f1949390b1c787fedeb0696256047bf459a Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 20 Sep 2024 14:38:29 -0400
Subject: fixed sorting by tags in card view

---
 .../views/collections/CollectionCardDeckView.tsx   | 45 +++++-----------------
 1 file changed, 10 insertions(+), 35 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 bcb42111f..d9c27254a 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
 import * as React from 'react';
 import { ClientUtils, DashColor, returnFalse, returnZero } from '../../../ClientUtils';
 import { emptyFunction } from '../../../Utils';
-import { Doc, StrListCast } from '../../../fields/Doc';
+import { Doc } from '../../../fields/Doc';
 import { DocData } from '../../../fields/DocSymbols';
 import { Id } from '../../../fields/FieldSymbols';
 import { List } from '../../../fields/List';
@@ -18,6 +18,7 @@ import { SnappingManager } from '../../util/SnappingManager';
 import { Transform } from '../../util/Transform';
 import { undoable } from '../../util/UndoManager';
 import { StyleProp } from '../StyleProp';
+import { TagItem } from '../TagsView';
 import { DocumentView } from '../nodes/DocumentView';
 import { GPTPopup, GPTPopupMode } from '../pdf/GPTPopup/GPTPopup';
 import './CollectionCardDeckView.scss';
@@ -242,7 +243,6 @@ export class CollectionCardView extends CollectionSubView() {
         const currRow = Math.floor((mouseY - 100) / rowHeight); //rows start at 0
 
         if (adjustedX < 0) {
-            console.log('DROP INDEX NO ');
             return 0; // Before the first column
         }
 
@@ -257,7 +257,6 @@ export class CollectionCardView extends CollectionSubView() {
 
             index = Math.floor(adjustedX / cardWidth) + currRow * this._maxRowCount;
         }
-        console.log('DROP INDEX = ' + index);
         return index;
     };
 
@@ -327,35 +326,11 @@ export class CollectionCardView extends CollectionSubView() {
      * @returns its value based on its tags
      */
 
-    tagValue = (doc: Doc) => {
-        const keys = Doc.MyFilterHotKeys;
-
-        const isTagActive = (key: Doc) => BoolCast(key.active);
-
-        let base = '';
-        let fraction = '';
-
-        keys.forEach(key => {
-            if (isTagActive(key)) {
-                if (base === '') {
-                    base = StrCast(key.toolType); // First active tag becomes the base
-                } else {
-                    fraction += StrCast(key.toolType); // Subsequent active tags become part of the fraction
-                }
-            }
-        });
-
-        // If no tag was active, return 0 by default
-        if (base === '') {
-            return 0;
-        }
-
-        // Construct the final number by appending the fraction if it exists
-        const numberString = fraction ? `${base}.${fraction}` : base;
-
-        // Convert the result to a number and return
-        return Number(numberString);
-    };
+    tagValue = (doc: Doc) =>
+        Doc.MyFilterHotKeys.map((key, i) => ({ has: TagItem.docHasTag(doc, StrCast(key.toolType)), i }))
+            .filter(({ has }) => has)
+            .map(({ i }) => i)
+            .join('.');
 
     /**
      * Called in the sortedDocsType method. Compares the cards' value in regards to the desired sort type-- earlier cards are move to the
@@ -492,7 +467,7 @@ export class CollectionCardView extends CollectionSubView() {
         };
         const docTextPromises = this.childDocsWithoutLinks.map(async doc => {
             const docText = (await docToText(doc)) ?? '';
-            doc['gptInputText'] = docText;
+            doc.gptInputText = docText;
             this._textToDoc.set(docText.replace(/\n/g, ' ').trim(), doc);
             return `======${docText.replace(/\n/g, ' ').trim()}======`;
         });
@@ -532,7 +507,7 @@ export class CollectionCardView extends CollectionSubView() {
 
         if (questionType === '2' || questionType === '4') {
             this.childDocs.forEach(d => {
-                d['chatFilter'] = false;
+                d.chatFilter = false;
             });
         }
 
@@ -573,7 +548,7 @@ export class CollectionCardView extends CollectionSubView() {
                     }
                     case '2':
                     case '4':
-                        doc['chatFilter'] = true;
+                        doc.chatFilter = true;
                         Doc.setDocFilter(DocCast(this.Document.embedContainer), 'chatFilter', true, 'match');
                         break;
                 }
-- 
cgit v1.2.3-70-g09d2

