-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
solution #1735
base: master
Are you sure you want to change the base?
solution #1735
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 is bad practice to write all the 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.
src/Components/Footer.tsx
Outdated
filter: 'all' | 'active' | 'completed'; | ||
handleFilterChenge: (newFilter: 'all' | 'active' | 'completed') => void; |
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 some custom type or enum and reuse 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.
Good job 👍
Let's improve your code
src/App.tsx
Outdated
const [title, setTitle] = useState<string>(''); | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const [error, setError] = useState<string | null>(null); | ||
const [filter, setFilter] = useState<FilterType>('all'); |
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/Components/ErrorNotification.tsx
Outdated
onClose, | ||
}) => ( | ||
<div | ||
className={`notification is-danger is-light has-text-weight-normal ${isVisible ? '' : 'hidden'}`} |
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
src/Components/Footer.tsx
Outdated
<a | ||
href="#/" | ||
className={`filter__link ${filter === 'all' ? 'selected' : ''}`} | ||
data-cy="FilterLinkAll" | ||
onClick={() => handleFilterChange('all')} | ||
> | ||
All | ||
</a> | ||
|
||
<a | ||
href="#/active" | ||
className={`filter__link ${filter === 'active' ? 'selected' : ''}`} | ||
data-cy="FilterLinkActive" | ||
onClick={() => handleFilterChange('active')} | ||
> | ||
Active | ||
</a> | ||
|
||
<a | ||
href="#/completed" | ||
className={`filter__link ${filter === 'completed' ? 'selected' : ''}`} | ||
data-cy="FilterLinkCompleted" | ||
onClick={() => handleFilterChange('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 Object.values(your created enum)
and render these options with map()
method
src/Components/Header.tsx
Outdated
только если все задачи выполнены. */} | ||
<button | ||
type="button" | ||
className={`todoapp__toggle-all ${todos.length > 0 && todos.every(todo => todo.completed) ? 'active' : ''}`} |
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 from jsx to the helper variable
src/Components/TodoItems.tsx
Outdated
/> | ||
</label> | ||
<span data-cy="TodoTitle" className="todo__title"> | ||
{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/TodoItems.tsx
Outdated
@@ -0,0 +1,50 @@ | |||
/* eslint-disable jsx-a11y/label-has-associated-control */ |
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.
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.
Well done
DEMO LINK