From 12695cc58fc0d029e865c8ef35c0f749f08bf175 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 19:58:53 +0200 Subject: [PATCH] working leantime widget 76 --- components/flow.tsx | 60 +++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 4a6b2a42..51e1d3b7 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -16,6 +16,7 @@ interface Task { editorId: string; editorFirstname: string | null; editorLastname: string | null; + userId: number; } interface ProjectSummary { @@ -71,27 +72,17 @@ export function Flow() { const fetchTasks = async (isRefresh = false) => { try { - if (isRefresh) setRefreshing(true); - + setLoading(true); const response = await fetch('/api/leantime/tasks'); - if (!response.ok) throw new Error('Failed to fetch tasks'); - const data = await response.json(); - console.log('Tasks API response:', data); - if (!data.tasks || !Array.isArray(data.tasks)) { - console.warn('No tasks found in response:', data); - setTasks([]); - return; - } - - // Sort tasks by status and date + // Filter and sort tasks const sortedTasks = data.tasks .filter((task: Task) => task.headline && typeof task.headline === 'string' && task.status !== 5 && // Not done - task.editorId === '2' // Only tasks assigned to user 2 + (task.editorId === '2' || task.userId === 2) // Tasks assigned to or owned by user 2 ) .sort((a: Task, b: Task) => { // Get valid dates for comparison @@ -99,19 +90,12 @@ export function Flow() { if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') { return new Date(task.dateToFinish).getTime(); } - return Number.MAX_SAFE_INTEGER; // Put tasks without due date at the end + return Number.MAX_SAFE_INTEGER; }; const dateA = getValidDate(a); const dateB = getValidDate(b); - - // Sort by date first - if (dateA !== dateB) { - return dateA - dateB; - } - - // If dates are equal, sort by status - return a.status - b.status; + return dateA - dateB; }); console.log('Filtered and sorted tasks:', sortedTasks); @@ -122,7 +106,6 @@ export function Flow() { setError('Failed to fetch tasks'); } finally { setLoading(false); - setRefreshing(false); } }; @@ -131,14 +114,14 @@ export function Flow() { }, []); return ( - + - Flow + Flow @@ -157,28 +140,25 @@ export function Flow() { {tasks.map((task) => (
-
+
{task.headline} -
-
- - {task.projectName} -
- - Unknown - +
+ + {task.projectName} + {task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00' && ( + + Due: {new Date(task.dateToFinish).toLocaleDateString()} + + )}