From eb09ffbaf5279bd5ef5fb40791fddd05d3980c72 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 15:23:01 +0200 Subject: [PATCH] working leantime widget 53 --- components/flow.tsx | 97 +++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index b88c98c0..1b020da7 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -24,24 +24,40 @@ interface ProjectSummary { } export function Flow() { - const [projects, setProjects] = useState([]); + const [tasks, setTasks] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const getStatusLabel = (status: number): string => { switch (status) { - case 1: - return 'NEW'; - case 2: - return 'INPROGRESS'; case 3: + return 'NEW'; + case 1: + case 4: + return 'INPROGRESS'; + case 2: + case 5: return 'DONE'; default: return 'UNKNOWN'; } }; + const getStatusColor = (status: number): string => { + const statusLabel = getStatusLabel(status); + switch (statusLabel) { + case 'DONE': + return 'bg-green-100 text-green-800'; + case 'INPROGRESS': + return 'bg-yellow-100 text-yellow-800'; + case 'NEW': + return 'bg-gray-100 text-gray-800'; + default: + return 'bg-gray-100 text-gray-800'; + } + }; + const fetchTasks = async (isRefresh = false) => { try { if (isRefresh) setRefreshing(true); @@ -51,32 +67,27 @@ export function Flow() { const data = await response.json(); if (!data.tasks || !Array.isArray(data.tasks)) { - setProjects([]); + setTasks([]); return; } - // Group tasks by project and count statuses - const projectMap = new Map>(); - - data.tasks.forEach((task: Task) => { - if (!projectMap.has(task.projectName)) { - projectMap.set(task.projectName, new Map()); - } - const statusMap = projectMap.get(task.projectName)!; - statusMap.set(task.status, (statusMap.get(task.status) || 0) + 1); + // Sort tasks by status (prioritizing in-progress and new tasks) and date + const sortedTasks = data.tasks.sort((a: Task, b: Task) => { + const statusA = getStatusLabel(a.status); + const statusB = getStatusLabel(b.status); + + // Prioritize INPROGRESS, then NEW, then DONE + const statusPriority: Record = { + 'INPROGRESS': 0, + 'NEW': 1, + 'DONE': 2, + 'UNKNOWN': 3 + }; + return (statusPriority[statusA] ?? 3) - (statusPriority[statusB] ?? 3); }); - // Convert to array format - const projectSummaries: ProjectSummary[] = Array.from(projectMap.entries()) - .map(([name, statusMap]) => ({ - name, - tasks: Array.from(statusMap.entries()).map(([status, count]) => ({ - status, - count - })) - })); - - setProjects(projectSummaries); + // Limit to 6 tasks + setTasks(sortedTasks.slice(0, 6)); setError(null); } catch (err) { console.error('Error fetching tasks:', err); @@ -112,26 +123,24 @@ export function Flow() { ) : error ? (
{error}
- ) : projects.length === 0 ? ( + ) : tasks.length === 0 ? (
No tasks found
) : ( -
- {projects.map((project) => ( -
-

{project.name}

-
- {project.tasks.map(({ status, count }) => ( -
- {count} - - {getStatusLabel(status)} - -
- ))} +
+ {tasks.map((task) => ( +
+
+
+

+ {task.headline} +

+ + {getStatusLabel(task.status)} + +
+

+ {task.projectName} +

))}