Sfoglia il codice sorgente

Fix My Due Cards to be sorted by due date, oldest first.

Thanks to xet7 !

Fixes #5956
Lauri Ojansivu 6 giorni fa
parent
commit
a540b12895
2 ha cambiato i file con 23 aggiunte e 7 eliminazioni
  1. 2 1
      client/components/main/dueCards.jade
  2. 21 6
      client/components/main/dueCards.js

+ 2 - 1
client/components/main/dueCards.jade

@@ -32,7 +32,8 @@ template(name="dueCards")
               span.global-search-error-messages
                 = msg
         else
-          +resultsPaged(this)
+          each card in dueCardsList
+            +resultCard(card)
 
 template(name="dueCardsViewChangePopup")
   if currentUser

+ 21 - 6
client/components/main/dueCards.js

@@ -31,6 +31,13 @@ Template.dueCards.helpers({
   userId() {
     return Meteor.userId();
   },
+  dueCardsList() {
+    const component = BlazeComponent.getComponentForElement(this);
+    if (component && component.dueCardsList) {
+      return component.dueCardsList();
+    }
+    return [];
+  },
 });
 
 BlazeComponent.extendComponent({
@@ -142,18 +149,26 @@ class DueCardsComponent extends CardSearchPagedComponent {
       });
     }
 
+    // Sort by due date: oldest first (ascending order)
     cards.sort((a, b) => {
-      const x = a.dueAt === null ? new Date('2100-12-31') : a.dueAt;
-      const y = b.dueAt === null ? new Date('2100-12-31') : b.dueAt;
+      // Handle null/undefined due dates by putting them at the end
+      const aDueAt = a.dueAt ? new Date(a.dueAt) : new Date('2100-12-31');
+      const bDueAt = b.dueAt ? new Date(b.dueAt) : new Date('2100-12-31');
 
-      if (x > y) return 1;
-      else if (x < y) return -1;
+      // Debug logging
+      if (process.env.DEBUG === 'true') {
+        console.log(`Comparing cards: "${a.title}" (${a.dueAt}) vs "${b.title}" (${b.dueAt})`);
+        console.log(`Parsed dates: ${aDueAt.toISOString()} vs ${bDueAt.toISOString()}`);
+        console.log(`Time difference: ${aDueAt.getTime() - bDueAt.getTime()}`);
+      }
 
-      return 0;
+      // Compare dates: if a is earlier than b, return negative (a comes first)
+      // if a is later than b, return positive (b comes first)
+      return aDueAt.getTime() - bDueAt.getTime();
     });
 
     // eslint-disable-next-line no-console
-    console.log('cards:', cards);
+    console.log('cards sorted by due date (oldest first):', cards);
     return cards;
   }
 }