From 1a41f773eb229028f50d63a936c5c78c4cd9e50a Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 15:26:56 +0200 Subject: [PATCH] working leantime widget 54 --- components/flow.tsx | 47 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 1b020da7..9885183d 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -12,7 +12,13 @@ interface Task { projectId: number; status: number; type: string; - dateToFinish: string | null; + dateToFinish: string; + date: string; + editFrom: string; + editTo: string; + authorFirstname?: string; + authorLastname?: string; + tags?: string; } interface ProjectSummary { @@ -58,6 +64,18 @@ export function Flow() { } }; + const getDateToSort = (task: Task): number => { + // Try different date fields in order of preference + const dates = [ + task.date, + task.dateToFinish, + task.editFrom, + task.editTo + ].filter(date => date && date !== '0000-00-00 00:00:00'); + + return dates.length > 0 ? new Date(dates[0]).getTime() : 0; + }; + const fetchTasks = async (isRefresh = false) => { try { if (isRefresh) setRefreshing(true); @@ -71,19 +89,9 @@ export function Flow() { return; } - // Sort tasks by status (prioritizing in-progress and new tasks) and date + // Sort tasks by date (oldest first) 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); + return getDateToSort(a) - getDateToSort(b); }); // Limit to 6 tasks @@ -138,9 +146,16 @@ export function Flow() { {getStatusLabel(task.status)} -

- {task.projectName} -

+
+

+ {task.projectName} +

+ {task.tags && ( +

+ {task.tags} +

+ )} +
))}