diff --git a/src/components/TempTodoItem.tsx b/src/components/TempTodoItem.tsx new file mode 100644 index 000000000..ecdc2003e --- /dev/null +++ b/src/components/TempTodoItem.tsx @@ -0,0 +1,33 @@ +/* eslint-disable jsx-a11y/label-has-associated-control */ +import classNames from 'classnames'; + +type Props = { + tempTodo: string; +}; + +export const TempTodoItem: React.FC = ({ tempTodo }) => { + return ( +
+ + + + {tempTodo} + + + {/* Remove button appears only on hover */} + + + {/* overlay will cover the todo while it is being deleted or updated */} +
+
+
+
+
+ ); +}; diff --git a/src/components/TodoItem.tsx b/src/components/TodoItem.tsx new file mode 100644 index 000000000..cf972db3f --- /dev/null +++ b/src/components/TodoItem.tsx @@ -0,0 +1,100 @@ +/* eslint-disable jsx-a11y/label-has-associated-control */ +import classNames from 'classnames'; +import { Todo } from '../types/Todo'; +import { FormEditingTitle } from './FormEditingTitle'; + +type Props = { + todo: Todo; + changeTodo: (todo: Todo) => void; + updatingAndDeletingCompletedTodos: Todo[] | []; + setUpdatingAndDeletingCompletedTodos: ( + deletingCompletedTodos: Todo[] | [], + ) => void; + editingTitle: number; + setEditingTitle: (editingTitle: number) => void; + titleEdit: string; + setTitleEdit: (titleEdit: string) => void; + handleChangeSubmit: (todo: Todo) => void; + deleteTodo: (todo: Todo) => void; +}; + +export const TodoItem: React.FC = ({ + todo, + changeTodo, + updatingAndDeletingCompletedTodos, + setUpdatingAndDeletingCompletedTodos, + editingTitle, + setEditingTitle, + titleEdit, + setTitleEdit, + handleChangeSubmit, + deleteTodo, +}) => { + const { id, completed, title } = todo; + + return ( +
+ + + {editingTitle === id ? ( + + ) : ( + <> + { + setEditingTitle(id); + setTitleEdit(title); + }} + > + {title} + + + + + )} + +
task.id === todo.id, + ), + })} + > +
+
+
+
+ ); +}; diff --git a/src/components/TodoList.tsx b/src/components/TodoList.tsx index f7a078d30..05f7f73e8 100644 --- a/src/components/TodoList.tsx +++ b/src/components/TodoList.tsx @@ -1,8 +1,7 @@ -/* eslint-disable jsx-a11y/label-has-associated-control */ -import classNames from 'classnames'; -import { Todo } from '../types/Todo'; import { useState } from 'react'; -import { FormEditingTitle } from './FormEditingTitle'; +import { Todo } from '../types/Todo'; +import { TempTodoItem } from './TempTodoItem'; +import { TodoItem } from './TodoItem'; type Props = { visibleTodos: Todo[]; @@ -54,111 +53,28 @@ export const TodoList: React.FC = ({ return (
{visibleTodos.map(todo => { - const { id, completed, title } = todo; - return ( -
- - - {editingTitle === id ? ( - - ) : ( - <> - { - setEditingTitle(id); - setTitleEdit(title); - }} - > - {title} - - - - - )} - - {/* overlay will cover the todo while it is being deleted or updated */} -
task.id === todo.id, - ), - })} - > -
-
-
-
+ ); })} - {tempTodo && ( -
- - - - {tempTodo} - - - {/* Remove button appears only on hover */} - - - {/* overlay will cover the todo while it is being deleted or updated */} -
-
-
-
-
- )} + {tempTodo && }
); };