diff --git a/components/flow.tsx b/components/flow.tsx index 1cb0da50..855cdaae 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -112,28 +112,36 @@ export function Flow() { return isValid; }) .sort((a: Task, b: Task) => { - // 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) + // First sort by dateToFinish (oldest first) const dateA = getValidDate(a); const dateB = getValidDate(b); // If both dates are valid, compare them if (dateA && dateB) { - return new Date(dateA).getTime() - new Date(dateB).getTime(); + const timeA = new Date(dateA).getTime(); + const timeB = new Date(dateB).getTime(); + if (timeA !== timeB) { + return timeA - timeB; + } } // 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 + // If dates are equal or neither has a date, sort by status (4 before others) + if (a.status === 4 && b.status !== 4) return -1; + if (b.status === 4 && a.status !== 4) return 1; + + // If status is also equal, maintain original order return 0; }); - console.log('Sorted tasks:', sortedTasks); + console.log('Sorted tasks:', sortedTasks.map(t => ({ + id: t.id, + date: t.dateToFinish, + status: t.status + }))); setTasks(sortedTasks.slice(0, 7)); } catch (error) { console.error('Error fetching tasks:', error);