import React from 'react'; import { useTranslation } from 'react-i18next'; import { CalendarDaysIcon } from '@heroicons/react/24/outline'; import TaskList from './TaskList'; import { Task } from '../../entities/Task'; import { Project } from '../../entities/Project'; import { sortTasksByPriorityDueDateProject } from '../../utils/taskSortUtils'; interface TodayPlanProps { todayPlanTasks: Task[] | undefined; projects: Project[]; onTaskUpdate: (task: Task) => Promise; onTaskDelete: (taskUid: string) => Promise; onToggleToday?: (taskId: number, task?: Task) => Promise; onTaskCompletionToggle?: (task: Task) => void; // New prop } const TodayPlan: React.FC = ({ todayPlanTasks, projects, onTaskUpdate, onTaskDelete, onToggleToday, onTaskCompletionToggle, // Destructure new prop }) => { const { t } = useTranslation(); // Handle undefined or null todayPlanTasks const safeTodayPlanTasks = todayPlanTasks || []; // Sort tasks to move in-progress tasks to the top, then apply multi-criteria sorting const sortedTasks = React.useMemo(() => { if (safeTodayPlanTasks.length === 0) return []; // Separate in-progress and non-in-progress tasks const inProgressTasks = safeTodayPlanTasks.filter( (task) => task.status === 'in_progress' || task.status === 1 ); const otherTasks = safeTodayPlanTasks.filter( (task) => task.status !== 'in_progress' && task.status !== 1 ); // Sort each group using multi-criteria sorting const sortedInProgress = sortTasksByPriorityDueDateProject(inProgressTasks); const sortedOthers = sortTasksByPriorityDueDateProject(otherTasks); // Return in-progress tasks first, followed by others return [...sortedInProgress, ...sortedOthers]; }, [safeTodayPlanTasks]); if (sortedTasks.length === 0) { return ( <>

{t( 'tasks.noPlanToday', 'No tasks planned for today yet' )}

{t( 'tasks.addToPlanHint', 'Click the "add to today plan" icon on the right of any task to add it here' )}

); } return ( <> ); }; export default TodayPlan;