From 50ecd1866c4ecff97b503ead1f2ecdd86761fe23 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 23:48:00 +0200 Subject: [PATCH] working leantime widget 135 --- components/flow.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 00d19c6f..1cb0da50 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -112,20 +112,25 @@ export function Flow() { return isValid; }) .sort((a: Task, b: Task) => { - // First sort by status (4 before 3) - if (a.status !== b.status) { - return a.status === 4 ? -1 : 1; - } + // First sort by status (4 before others) + if (a.status === 4 && b.status !== 4) return -1; + if (b.status === 4 && a.status !== 4) return 1; // Then sort by dateToFinish (oldest first) const dateA = getValidDate(a); const dateB = getValidDate(b); - if (!dateA && !dateB) return 0; - if (!dateA) return 1; - if (!dateB) return -1; + // If both dates are valid, compare them + if (dateA && dateB) { + return new Date(dateA).getTime() - new Date(dateB).getTime(); + } - return new Date(dateA).getTime() - new Date(dateB).getTime(); + // If only one date is valid, put the task with a date first + if (dateA) return -1; + if (dateB) return 1; + + // If neither has a date, maintain their original order + return 0; }); console.log('Sorted tasks:', sortedTasks);