diff --git a/frontend/components/Task/TasksToday.tsx b/frontend/components/Task/TasksToday.tsx index 2bca620..a2052de 100644 --- a/frontend/components/Task/TasksToday.tsx +++ b/frontend/components/Task/TasksToday.tsx @@ -596,8 +596,74 @@ const TasksToday: React.FC = () => { useStore.getState().tasksStore.updateTaskInStore(updatedTask); try { - // Make API call to persist the change - await updateTask(updatedTask.id, updatedTask); + // Make API call to persist the change and get the updated task from server + const updatedTaskFromServer = await updateTask( + updatedTask.id, + updatedTask + ); + + // Update the UI again with the actual server response to ensure consistency + setMetrics((prevMetrics) => { + const newMetrics = { ...prevMetrics }; + + // Helper to update task in a list with server data + const updateTaskInList = (list: Task[]) => { + return list.map((task) => + task.id === updatedTaskFromServer.id + ? { + ...task, + ...updatedTaskFromServer, + subtasks: + updatedTaskFromServer.subtasks || + updatedTaskFromServer.Subtasks || + task.subtasks || + task.Subtasks || + [], + Subtasks: + updatedTaskFromServer.subtasks || + updatedTaskFromServer.Subtasks || + task.subtasks || + task.Subtasks || + [], + } + : task + ); + }; + + // Update task in all relevant lists with server data + if (newMetrics.today_plan_tasks) { + newMetrics.today_plan_tasks = updateTaskInList( + newMetrics.today_plan_tasks + ); + } + if (newMetrics.suggested_tasks) { + newMetrics.suggested_tasks = updateTaskInList( + newMetrics.suggested_tasks + ); + } + if (newMetrics.tasks_due_today) { + newMetrics.tasks_due_today = updateTaskInList( + newMetrics.tasks_due_today + ); + } + if (newMetrics.tasks_in_progress) { + newMetrics.tasks_in_progress = updateTaskInList( + newMetrics.tasks_in_progress + ); + } + if (newMetrics.tasks_completed_today) { + newMetrics.tasks_completed_today = updateTaskInList( + newMetrics.tasks_completed_today + ); + } + + return newMetrics; + }); + + // Also update the store with server response + useStore + .getState() + .tasksStore.updateTaskInStore(updatedTaskFromServer); } catch (error) { console.error('Error updating task:', error); // Revert UI on error if necessary, or re-fetch to sync