From 23b5cf68b4c65f042b4562fed6588616c32858f6 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 20:36:16 +0200 Subject: [PATCH] working leantime widget 85 --- components/flow.tsx | 73 +++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 01bee0d5..1a2bdaf5 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -9,24 +9,33 @@ import { Badge } from "@/components/ui/badge"; interface Task { id: number; headline: string; - userId: number; + description: string; + dateToFinish: string; + date: string; + projectId: number; + projectName: string; status: number; - editorId: string; - assignedTo?: any; - projectName?: string; - dateToFinish?: string; - date?: string; + editorId?: string; + editorFirstname?: string; + editorLastname?: string; + authorFirstname: string; + authorLastname: string; + milestoneHeadline?: string; } -interface ApiResponse { - jsonrpc: string; - result: Task[]; +interface ProjectSummary { + name: string; + tasks: { + status: number; + count: number; + }[]; } export function Flow() { 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) { @@ -72,28 +81,24 @@ export function Flow() { if (!response.ok) { throw new Error('Failed to fetch tasks'); } - const data: ApiResponse = await response.json(); + const data = await response.json(); - // Extract tasks from the result property - const tasksList = data.result || []; - - if (!Array.isArray(tasksList)) { - console.warn('No tasks found in response', tasksList); + if (!Array.isArray(data)) { + console.warn('No tasks found in response', data as unknown); setTasks([]); return; } - // Sort tasks by date and limit to 4 - const sortedTasks = tasksList + // Sort tasks by due date (oldest first) + const sortedTasks = data .sort((a: Task, b: Task) => { - const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() : - a.date ? new Date(a.date).getTime() : Date.now(); - const dateB = b.dateToFinish ? new Date(b.dateToFinish).getTime() : - b.date ? new Date(b.date).getTime() : Date.now(); + const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() : new Date(a.date).getTime(); + const dateB = b.dateToFinish ? new Date(b.dateToFinish).getTime() : new Date(b.date).getTime(); return dateA - dateB; }) - .slice(0, 4); // Limit to 4 tasks + .slice(0, 6); // Limit to 6 tasks + console.log('Sorted and filtered tasks:', sortedTasks); setTasks(sortedTasks); } catch (error) { console.error('Error fetching tasks:', error); @@ -110,7 +115,7 @@ export function Flow() { return ( - Flow + Flow - + {loading ? (
@@ -130,30 +135,26 @@ export function Flow() { ) : tasks.length === 0 ? (
No tasks found
) : ( -
+
{tasks.map((task) => (
-
+
{task.headline} -
- {task.projectName && ( - <> - - {task.projectName} - - )} +
+ + {task.projectName} {task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00' && ( - + Due: {new Date(task.dateToFinish).toLocaleDateString()} )}