diff --git a/components/flow.tsx b/components/flow.tsx index db42c46e..94ccce38 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -81,6 +81,7 @@ 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; } @@ -94,32 +95,29 @@ export function Flow() { const data = await response.json(); if (!Array.isArray(data)) { - console.warn('No tasks found in response'); + console.warn('No tasks found in response', data as unknown); setTasks([]); return; } - // 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(); + // 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(); }); - console.log('Number of tasks found:', sortedTasks.length); + console.log('Sorted tasks by dateToFinish:', sortedTasks); setTasks(sortedTasks.slice(0, 6)); } catch (error) { - console.error('Error fetching tasks'); + console.error('Error fetching tasks:', error); setError('Failed to fetch tasks'); } finally { setLoading(false); @@ -135,8 +133,8 @@ export function Flow() { if (!task.validDate) { return ( <> - NO - DATE + NO + DATE ); } @@ -148,27 +146,23 @@ export function Flow() { try { const month = task.validDate.toLocaleString('fr-FR', { month: 'short' }).toUpperCase(); const day = task.validDate.getDate(); - const year = task.validDate.getFullYear(); return ( <> - + {month} - + {day} - - {year} - ); } catch (error) { - console.error('Error formatting date for task', task.id); + console.error('Error formatting date for task', task.id, error); return ( <> - ERR - DATE + ERR + DATE ); } @@ -176,48 +170,48 @@ export function Flow() { return ( - - Flow + + Flow - + {loading ? ( -
-
+
+
) : error ? ( -
{error}
+
{error}
) : tasks.length === 0 ? ( -
No tasks with due dates found
+
No tasks with due dates found
) : ( -
+
{tasks.map((task) => (
-
-
+
+
-
+
{task.headline} -
- +
+ {task.projectName}