From 1f508923cbea725d98eec4cfb308cb028502db3a Mon Sep 17 00:00:00 2001 From: Italo Magno Date: Fri, 15 Nov 2024 17:47:48 -0300 Subject: [PATCH] this will be the last time --- src/components/TodoList.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/TodoList.tsx b/src/components/TodoList.tsx index e3e8e1cbf..cd67c70fc 100644 --- a/src/components/TodoList.tsx +++ b/src/components/TodoList.tsx @@ -89,6 +89,20 @@ export function TodoList({ } } + async function handleRemoveTodo(todoId: number) { + try { + setEditingTodosId([...editingTodosId, todoId]); + await deleteTodo(todoId); + setEditingTodosId(editingTodosId.filter(id => id !== todoId)); + setTodos(todos.filter(t => t.id !== todoId)); + setFilteredTodos(filteredTodos.filter(t => t.id !== todoId)); + } catch (e) { + setError('Unable to delete a todo'); + setEditingTodosId(editingTodosId.filter(id => id !== todoId)); + } + } + + /* async function handleRemoveTodo(todoId: number) { setEditingTodosId([...editingTodosId, todoId]); try { @@ -107,7 +121,7 @@ export function TodoList({ setEditingTodosId(editingTodosId.filter(id => id !== todoId)); } } - + */ async function handleEditTodoTitle( e: React.FormEvent, todo: Todo,