Fix today task name change (#552)

* Update tasks in today page on task modal edit

* fixup! Update tasks in today page on task modal edit
This commit is contained in:
Chris 2025-11-16 23:29:01 +02:00 committed by GitHub
parent ff304f53d5
commit e47e2f5ffa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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