From 6c138e4a7923f19b83125b16e4696a9489845928 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 21:17:18 +0200 Subject: [PATCH] working leantime widget 98 --- components/flow.tsx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 498a23b6..0757faa6 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -97,12 +97,7 @@ export function Flow() { // Debug log to see all tasks and their dates data.tasks.forEach((task: Task) => { - console.log(`Task ${task.id} - ${task.headline} dates:`, { - dateToFinish: task.dateToFinish, - editFrom: task.editFrom, - editTo: task.editTo, - date: task.date - }); + console.log(`Task ${task.id} - ${task.headline}:`, task); }); const getValidDate = (task: Task): Date | undefined => { @@ -144,17 +139,24 @@ export function Flow() { if (a.validDate && b.validDate) { return a.validDate.getTime() - b.validDate.getTime(); } - // If only one task has a date, put it first - if (a.validDate) return -1; - if (b.validDate) return 1; - // If neither has a date, sort by ID - return a.id - b.id; + // If neither has a date, sort by ID (most recent first) + if (!a.validDate && !b.validDate) { + return b.id - a.id; // Reverse ID sort for undated tasks + } + // Put tasks without dates at the end + if (!a.validDate) return 1; + if (!b.validDate) return -1; + return 0; }); console.log('Final sorted tasks:', sortedTasks.map((t: TaskWithDate) => ({ id: t.id, headline: t.headline, - date: t.validDate?.toISOString() + date: t.validDate?.toISOString(), + status: t.status, + dateToFinish: t.dateToFinish, + editFrom: t.editFrom, + editTo: t.editTo }))); setTasks(sortedTasks);