From 94aac5fc4acb9b906ab972c308adc274f25fa012 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 22:58:15 +0200 Subject: [PATCH] working leantime widget 119 --- components/flow.tsx | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 47b951f2..db42c46e 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -81,7 +81,6 @@ export function Flow() { }; const getValidDate = (task: Task): string | null => { - // Only use dateToFinish if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') { return task.dateToFinish; } @@ -100,21 +99,23 @@ export function Flow() { return; } - // Filter out completed tasks (status 3) and sort by dateToFinish - const sortedTasks = data - .filter((task: Task) => task.status !== 3) - .sort((a: Task, b: Task) => { - const dateA = getValidDate(a); - const dateB = getValidDate(b); - - if (!dateA && !dateB) return 0; - if (!dateA) return 1; - if (!dateB) return -1; - - return new Date(dateA).getTime() - new Date(dateB).getTime(); + // Process tasks with valid dates + const processedTasks = data.map((task: Task) => { + const dateStr = getValidDate(task); + return { + ...task, + validDate: dateStr ? new Date(dateStr) : undefined + }; + }); + + // Filter and sort tasks - include status 3 (In Progress) + const sortedTasks = processedTasks + .filter((task: TaskWithDate) => task.validDate) // Only keep tasks with valid dates + .sort((a: TaskWithDate, b: TaskWithDate) => { + if (!a.validDate || !b.validDate) return 0; + return a.validDate.getTime() - b.validDate.getTime(); }); - // Only log the count of tasks for security console.log('Number of tasks found:', sortedTasks.length); setTasks(sortedTasks.slice(0, 6)); } catch (error) {