From 36f4105e45477de6343bad61f7b2003e1b25bc6d Mon Sep 17 00:00:00 2001 From: Daria Nastas Date: Mon, 18 Nov 2024 16:51:59 +0200 Subject: [PATCH] add task solution --- src/App.tsx | 8 +++++--- src/components/TodoItem.tsx | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e005ee3e4..4ab4db298 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -95,16 +95,18 @@ export const App: React.FC = () => { const handleDeleteTodo = async (todoId: number) => { setIsLoading(curr => [...curr, todoId]); - deleteTodo(todoId) + return deleteTodo(todoId) .then(() => setTodos(currentTodos => currentTodos.filter(todo => todo.id !== todoId), ), ) - .catch(() => setError(errorMessages.delete)) + .catch(() => { + setError(errorMessages.delete); + throw new Error('not deleted'); + }) .finally(() => { setIsLoading(curr => curr.filter(delTodoId => delTodoId !== todoId)); - inputRef.current?.focus(); }); }; diff --git a/src/components/TodoItem.tsx b/src/components/TodoItem.tsx index 5232e3cff..f3fe355fd 100644 --- a/src/components/TodoItem.tsx +++ b/src/components/TodoItem.tsx @@ -4,7 +4,7 @@ import { Todo } from '../types/Todo'; interface Props { todo: Todo; - onRemoveTodo?: (todoId: number) => Promise; + onRemoveTodo?: (todoId: number) => void; onToggleTodoCompletion?: (todo: Todo) => void; onUpdateTodoTitle?: (todo: Todo) => Promise; isLoading: boolean;