-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Todo app #1495
base: master
Are you sure you want to change the base?
Todo app #1495
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.
Good job 👍
Let's improve your code
It's bad practice to write so much code in one component, you need to separate the logic into different components, for example Header, Footer, TodoItem, TodoList
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.
Almost done!
Let's make your code better
src/App.tsx
Outdated
case 'All': | ||
visibleTodos = todos; | ||
break; | ||
case 'Active': | ||
visibleTodos = todos.filter(todo => !todo.completed); | ||
break; | ||
case '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.
Create a enum for 'All', 'Active', 'Completed' and use it everywhere
src/App.tsx
Outdated
//#endregion | ||
|
||
//#region add Todos | ||
// input |
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.
Remove all comments, it's redundant here
src/App.tsx
Outdated
titleRef={titleRef} | ||
/> | ||
|
||
{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 && ( |
src/components/Footer/Footer.tsx
Outdated
return ( | ||
<footer className="footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{todos.filter(todo => !todo.completed).length} items left |
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 helper variable and use it here
src/components/Footer/Footer.tsx
Outdated
<a | ||
href="#/" | ||
className={cn('filter__link', { | ||
selected: selectedFilter === 'All', | ||
})} | ||
data-cy="FilterLinkAll" | ||
onClick={onFilterAll} | ||
> | ||
All | ||
</a> | ||
|
||
<a | ||
href="#/active" | ||
className={cn('filter__link', { | ||
selected: selectedFilter === 'Active', | ||
})} | ||
data-cy="FilterLinkActive" | ||
onClick={onFilterActive} | ||
> | ||
Active | ||
</a> | ||
|
||
<a | ||
href="#/completed" | ||
className={cn('filter__link', { | ||
selected: selectedFilter === 'Completed', | ||
})} | ||
data-cy="FilterLinkCompleted" | ||
onClick={onFilterCompleted} | ||
> | ||
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 created enum)
and render these options with map()
method
src/components/Header/Header.tsx
Outdated
}) => { | ||
return ( | ||
<header className="header"> | ||
{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 && ( |
src/components/Header/Header.tsx
Outdated
active: todos.every(todo => todo.completed), | ||
})} | ||
data-cy="ToggleAllButton" | ||
onClick={() => onToggleAll()} |
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.
onClick={() => onToggleAll()} | |
onClick={onToggleAll} |
src/components/TodoItem/TodoItem.tsx
Outdated
data-cy="TodoStatus" | ||
type="checkbox" | ||
className="todo__status" | ||
checked={todo.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 destructuring for todo
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.
- show loaders on todos that you need to update on toggle all
- show loaders on todos that you need to delete on completedAll
Screen.Recording.2024-10-25.at.10.08.32.mov
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.
Great! 🔥
//#endregion | ||
|
||
//#region rename Todo | ||
const [redactingQuery, setRedactingQuery] = useState(selectedTodo?.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.
All states must be declared at the beginning of the component
DEMO LINK