From 52f165ba91a02cd4284aa3e622914ec7815ee106 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 22:41:25 +0200 Subject: [PATCH] working leantime widget 114 --- components/flow.tsx | 93 +++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 62 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 0ad0da52..6768cbf3 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -95,40 +95,21 @@ export function Flow() { return; } - // Log the complete first task to see its structure - console.log('First task from API:', JSON.stringify(data.tasks[0], null, 2)); - - // Log all tasks with their date fields - data.tasks.forEach((task: Task) => { - console.log(`Task ${task.id} - ${task.headline}:`, { - dateToFinish: task.dateToFinish || 'not set', - date: task.date || 'not set', - status: task.status, - projectName: task.projectName - }); - }); - // Process tasks - exclude completed tasks and get valid dates const processedTasks = data.tasks .filter((task: Task) => task.status !== 5) // Exclude completed tasks .map((task: Task): TaskWithDate => { let validDate: Date | undefined; - // First try dateToFinish if it's a valid date + // Only use dateToFinish if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') { - const date = new Date(task.dateToFinish); - if (!isNaN(date.getTime())) { - validDate = date; - console.log(`Task ${task.id} - Valid dateToFinish:`, task.dateToFinish); - } - } - - // If no valid dateToFinish, try date field - if (!validDate && task.date && task.date !== '0000-00-00 00:00:00') { - const date = new Date(task.date); - if (!isNaN(date.getTime())) { - validDate = date; - console.log(`Task ${task.id} - Using date field:`, task.date); + const dateToFinish = new Date(task.dateToFinish); + if (!isNaN(dateToFinish.getTime())) { + validDate = dateToFinish; + console.log(`Task ${task.id} - ${task.headline}:`, { + dateToFinish: task.dateToFinish, + status: task.status + }); } } @@ -136,40 +117,28 @@ export function Flow() { }); // Sort tasks: first by status (4 before 3), then by date - const sortedTasks = processedTasks - .sort((a: TaskWithDate, b: TaskWithDate) => { - // First sort by status (4 before 3) - if (a.status !== b.status) { - return b.status - a.status; // Higher status numbers first - } - - // Then sort by date - if (a.validDate && b.validDate) { - return a.validDate.getTime() - b.validDate.getTime(); - } - if (a.validDate) return -1; - if (b.validDate) return 1; - return 0; - }); + const sortedTasks = processedTasks.sort((a: TaskWithDate, b: TaskWithDate) => { + // First sort by status (4 before 3) + if (a.status !== b.status) { + return b.status - a.status; + } + + // Then sort by date + if (a.validDate && b.validDate) { + return a.validDate.getTime() - b.validDate.getTime(); + } + if (a.validDate) return -1; + if (b.validDate) return 1; + return 0; + }); - console.log('Sorted tasks before slice:', sortedTasks.map((t: TaskWithDate) => ({ - id: t.id, - headline: t.headline, - status: t.status, - dateToFinish: t.dateToFinish, - date: t.date, - validDate: t.validDate?.toISOString() - }))); - - // Take the first 12 tasks + // Take first 12 tasks const finalTasks = sortedTasks.slice(0, 12); - console.log('Final tasks to display:', finalTasks.map((t: TaskWithDate) => ({ id: t.id, headline: t.headline, status: t.status, dateToFinish: t.dateToFinish, - date: t.date, validDate: t.validDate?.toISOString() }))); @@ -199,24 +168,24 @@ export function Flow() { const today = new Date(); today.setHours(0, 0, 0, 0); - const isPastDue = task.validDate < today; - const textColorClass = isPastDue ? 'text-red-600' : 'text-blue-600'; - const boldColorClass = isPastDue ? 'text-red-700' : 'text-blue-700'; try { + const month = task.validDate.toLocaleString('fr-FR', { month: 'short' }).toUpperCase(); + const day = task.validDate.getDate(); + return ( <> - - {new Intl.DateTimeFormat('fr-FR', { month: 'short' }).format(task.validDate)} + + {month} - - {task.validDate.getDate()} + + {day} ); } catch (error) { - console.error('Error formatting date:', error); + console.error('Error formatting date for task', task.id, error); return ( <> ERR