-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #1056
base: master
Are you sure you want to change the base?
Develop #1056
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/TodoList.tsx
Outdated
switch (filter) { | ||
case Filter.ACTIVE: | ||
return !todo.completed; | ||
case Filter.COMPLETED: | ||
return todo.completed; | ||
default: | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move filter inside swith to avoid extra iteration in default case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/header.tsx
Outdated
useEffect(() => { | ||
const savedTodos = localStorage.getItem('todos'); | ||
|
||
if (savedTodos) { | ||
setTodos(JSON.parse(savedTodos)); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
useEffect(() => { | ||
localStorage.setItem('todos', JSON.stringify(todos)); | ||
}, [todos]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need it in the header, move into state.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what looks strange?))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/TodoList.tsx
Outdated
); | ||
} | ||
|
||
function handleUpdateTodo(id: number, newTitle: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is important to stick to one way of creating functions, fix it everywhere
function handleUpdateTodo(id: number, newTitle: string) { | |
const handleUpdateTodo = (id: number, newTitle: string) => { |
src/components/TodoList.tsx
Outdated
{filteredTodos.map((todo: Todo) => ( | ||
<div | ||
data-cy="Todo" | ||
className={`todo ${todo.completed ? 'completed' : ''}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the classnames library for add classes with condition. Fix it everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why i need use this lebrary? for me vanilla is better =)
src/components/footer.tsx
Outdated
<a | ||
href="#/" | ||
className={`filter__link ${filter === Filter.ALL ? 'selected' : ''}`} | ||
data-cy="FilterLinkAll" | ||
onClick={() => handleFilterChange(Filter.ALL)} | ||
> | ||
All | ||
</a> | ||
|
||
<a | ||
href="#/active" | ||
className={`filter__link ${filter === Filter.ACTIVE ? 'selected' : ''}`} | ||
data-cy="FilterLinkActive" | ||
onClick={() => handleFilterChange(Filter.ACTIVE)} | ||
> | ||
Active | ||
</a> | ||
|
||
<a | ||
href="#/completed" | ||
className={`filter__link ${filter === Filter.COMPLETED ? 'selected' : ''}`} | ||
data-cy="FilterLinkCompleted" | ||
onClick={() => handleFilterChange(Filter.COMPLETED)} | ||
> | ||
Completed | ||
</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Object.values(your enum)
and render these options with map()
method
className="todo__title" | ||
onDoubleClick={() => setEditingTodoId(todo.id)} | ||
> | ||
{todo.title} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use destructuring for todo
src/components/header.tsx
Outdated
onClick={() => { | ||
const allCompleted = todos.every((todo: Todo) => todo.completed); | ||
|
||
setTodos((currentTodos: Todo[]) => | ||
currentTodos.map((todo: Todo) => ({ | ||
...todo, | ||
completed: !allCompleted, | ||
})), | ||
); | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this logic to the handler function
src/components/state.tsx
Outdated
value={{ | ||
todos, | ||
setTodos, | ||
title, | ||
setTitle, | ||
filter, | ||
setFilter, | ||
editingTodoId, | ||
setEditingTodoId, | ||
deleteTodo, | ||
inputRef, | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these values to the object and pass it here
src/components/footer.tsx
Outdated
|
||
return ( | ||
<> | ||
{todos.length > 0 ? ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{todos.length > 0 ? ( | |
{todos.length > 0 && ( |
src/components/TodoList.tsx
Outdated
{filteredTodos.map((todo: Todo) => ( | ||
<div | ||
data-cy="Todo" | ||
className={`todo ${todo.completed ? 'completed' : ''}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
className={`todo ${todo.completed ? 'completed' : ''}`} | |
className={cn('todo', {'completed':todo.completed})} |
it's looks much better
also if we will need to add some another class here
without classnames:
className={`todo ${todo.completed ? 'completed' : ''} ${smth ? 'test-class' : ''}`}
with classnames:
className={cn('todo', {'completed':todo.completed, 'test-class': smth})}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job
DEMO LINK