-
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
add task solution #812
base: master
Are you sure you want to change the base?
add task solution #812
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 work! 🔥
I leave some comments for you!
.catch(() => { | ||
setErrorMesssage('Unable to load todos'); | ||
|
||
setTimeout(() => { |
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.
I think you need to clear this timeout
data-cy="HideErrorButton" | ||
type="button" | ||
className="delete" | ||
onClick={() => onErrorMesssageChange('')} |
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.
You can use your const removeErrorMessage here i think
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 point.
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, but there is quite a bit of work to be done.
src/App.tsx
Outdated
/* eslint-disable max-len */ | ||
/* eslint-disable jsx-a11y/control-has-associated-label */ |
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.
Try to rewrite the code so that it is not necessary to disable the linter
src/App.tsx
Outdated
|
||
const [title, setTitle] = useState(''); | ||
const [tempTodo, setTempTodo] = useState<Todo | null>(null); | ||
const [isDisable, setIsDisable] = useState(false); |
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.
const [isDisable, setIsDisable] = useState(false); | |
const [isDisabled, setIsDisabled] = useState(false); |
src/App.tsx
Outdated
onErrorMesssageChange={setErrorMesssage} | ||
/> | ||
|
||
{filteredTodos.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.
{filteredTodos.length > 0 && ( | |
{!!filteredTodos.length && ( |
src/App.tsx
Outdated
/> | ||
)} | ||
|
||
{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/App.tsx
Outdated
onSelectedFilter={setSelectedFilter} | ||
/> | ||
)} | ||
|
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.
return ( | ||
<footer className="todoapp__footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{`${countTodos(todos, false)} 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.
If there is one item, there should not be a plural in the text.
@@ -0,0 +1,102 @@ | |||
/* eslint-disable jsx-a11y/control-has-associated-label */ |
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.
Try to rewrite the code so that it is not necessary to disable the linter
src/components/TodoItem/TodoItem.tsx
Outdated
@@ -0,0 +1,162 @@ | |||
/* eslint-disable max-len */ |
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.
Try to rewrite the code so that it is not necessary to disable the linter
src/components/TodoItem/TodoItem.tsx
Outdated
}; | ||
|
||
const updateTitle = () => { | ||
if (editedTitle.trim() === 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.
You use editedTitle.trim()
three times, it's better to put it in a variable and reuse it.
src/components/TodoItem/TodoItem.tsx
Outdated
data-cy="Todo" | ||
key={todo.id} | ||
className={classNames('todo', { | ||
completed: todo.completed === 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.
completed: todo.completed === true, | |
completed: 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.
Good work 👍
Left a few suggestons
setTempTodo({ | ||
id: 0, | ||
userId: USER_ID, | ||
title: title.trim(), | ||
completed: false, | ||
}); | ||
|
||
setIsDisabled(true); | ||
|
||
addTodo({ | ||
userId: USER_ID, | ||
title: title.trim(), | ||
completed: false, | ||
}) |
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.
setTempTodo({ | |
id: 0, | |
userId: USER_ID, | |
title: title.trim(), | |
completed: false, | |
}); | |
setIsDisabled(true); | |
addTodo({ | |
userId: USER_ID, | |
title: title.trim(), | |
completed: false, | |
}) | |
const newTodo = { | |
userId: USER_ID, | |
title: title.trim(), | |
completed: false, | |
}; | |
setTempTodo({ | |
...newTodo, | |
id: 0, | |
}); | |
setIsDisabled(true); | |
addTodo(newTodo) |
Don't repeat yourself
setTimeout(() => { | ||
setErrorMesssage(''); | ||
}, 3000); |
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.
You can trigger timeout in the ErrorNotification
component in case of any error
return ( | ||
<footer className="todoapp__footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{`${countTodos(todos, false)} ${countTodos(todos, false) === 1 ? 'item' : '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.
countTodos(todos, false)
You do it twice here, create a variable
let todosCopy = [...todos]; | ||
|
||
if (selectedFilter) { | ||
todosCopy = todosCopy.filter(({ completed }) => { | ||
switch (selectedFilter) { | ||
case FilterStatus.Active: | ||
return !completed; | ||
case FilterStatus.Completed: | ||
return completed; | ||
default: | ||
return todosCopy; |
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.
In the default case, you get an array of todosCopy
arrays. And filter
creates a new array so you don't need to create copy in this case
DEMO LINK