diff --git a/components/flow.tsx b/components/flow.tsx index 82ab93d..3a71013 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -117,14 +117,31 @@ export function Duties() { } // Backend already filters out status=5 (Done) and filters by editorId - // Only sort by dateToFinish here - const sortedTasks = data + // Filter to keep only tasks with due date before today (past due) + const today = new Date(); + today.setHours(0, 0, 0, 0); // Set to start of today for accurate comparison + + const filteredTasks = data.filter((task: Task) => { + const dueDate = getValidDate(task); + if (!dueDate) { + return false; // Exclude tasks without a due date + } + + const taskDueDate = new Date(dueDate); + taskDueDate.setHours(0, 0, 0, 0); // Set to start of day for accurate comparison + + // Keep only tasks with due date before today (past due) + return taskDueDate < today; + }); + + // Sort by dateToFinish (oldest first) + const sortedTasks = filteredTasks .sort((a: Task, b: Task) => { // First sort by dateToFinish (oldest first) const dateA = getValidDate(a); const dateB = getValidDate(b); - // If both dates are valid, compare them + // Both dates are guaranteed to exist after filtering if (dateA && dateB) { const timeA = new Date(dateA).getTime(); const timeB = new Date(dateB).getTime(); @@ -133,11 +150,7 @@ export function Duties() { } } - // If only one date is valid, put the task with a date first - if (dateA) return -1; - if (dateB) return 1; - - // If dates are equal or neither has a date, sort by status (4 before others) + // If dates are equal, sort by status (4 before others) if (a.status === 4 && b.status !== 4) return -1; if (b.status === 4 && a.status !== 4) return 1; @@ -261,7 +274,7 @@ export function Duties() { ) : error ? (