-
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 rename todo and completed status todo #807
base: master
Are you sure you want to change the base?
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, 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
.then(setTodos) | ||
.catch((error) => { | ||
setErrorMessage(TodosError.DOWNLOAD_ERROR_MESSAGE); | ||
throw error; |
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.
throw error; | |
throw Error(error.message); |
Fix this in all code.
src/App.tsx
Outdated
}); | ||
}, []); | ||
|
||
const timerId = useRef<number>(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.
const timerId = useRef<number>(0); | |
const timerIdRef = useRef<number>(0); |
src/App.tsx
Outdated
useEffect(() => { | ||
if (timerId.current) { | ||
window.clearTimeout(timerId.current); | ||
} | ||
|
||
timerId.current = window.setTimeout(() => { | ||
setErrorMessage(''); | ||
}, 3000); | ||
}, [errorMessage]); |
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/App.tsx
Outdated
<h1 className="todoapp__title">todos</h1> | ||
|
||
<div className="todoapp__content"> | ||
|
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/Header.tsx
Outdated
|
||
return ( | ||
<header className="todoapp__header"> | ||
{/* this buttons is active only if there are some active 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.
Do not leave unnecessary comments.
src/components/Header/Header.tsx
Outdated
className="todoapp__toggle-all active" | ||
data-cy="ToggleAllButton" | ||
/> | ||
{/* Add a todo on form submit */} |
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.
Do not leave unnecessary comments.
src/components/Loader/Loader.tsx
Outdated
'modal', | ||
'overlay', | ||
{ | ||
'is-active': isProcessing || todoId === 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.
'is-active': isProcessing || todoId === 0, | |
'is-active': isProcessing || !todoId, |
src/components/TodoItem/TodoItem.tsx
Outdated
} | ||
}; | ||
|
||
const titleInput = useRef<HTMLInputElement | null>(null); |
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 titleInput = useRef<HTMLInputElement | null>(null); | |
const titleInputRef = useRef<HTMLInputElement | null>(null); |
src/components/TodoItem/TodoItem.tsx
Outdated
onClick={() => { | ||
onDeleteTodo(); | ||
}} |
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={() => { | |
onDeleteTodo(); | |
}} | |
onClick={onDeleteTodo} |
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!
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.
src/App.tsx
Outdated
if (isAllCompleted) { | ||
Promise.all(visibleTodos.map(updateTodoStatus)); | ||
} else { | ||
Promise.all(activeTodos.map(updateTodoStatus)); | ||
} |
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.
"DRY"
if (isAllCompleted) { | |
Promise.all(visibleTodos.map(updateTodoStatus)); | |
} else { | |
Promise.all(activeTodos.map(updateTodoStatus)); | |
} | |
const todosForUpdate = isAllCompleted ? visibleTodos : activeTodos; | |
Promise.all(todosForUpdate.map(updateTodoStatus)); |
src/App.tsx
Outdated
/> | ||
|
||
<section className="todoapp__main" data-cy="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.
Not fixed 😢
src/components/Footer/Footer.tsx
Outdated
: `${todosLength} items left`} | ||
</span> | ||
|
||
{/* Active filter should have a 'selected' class */} |
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.
Not fixed 😢
src/components/Footer/Footer.tsx
Outdated
type="button" | ||
className="todoapp__clear-completed" | ||
data-cy="ClearCompletedButton" | ||
style={{ visibility: completedTodosLength ? 'visible' : '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.
Nit fixed 😢
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 are some not fixed issues. Please, pay attention))
src/App.tsx
Outdated
.then(setTodos) | ||
.catch((error) => { | ||
setErrorMessage(TodosError.DOWNLOAD_ERROR_MESSAGE); | ||
throw Error(error.message); |
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 seems that your error message is in 'errorMessage', which you set on previous line, also add new 'throw new Error'
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.
We can pass a pure error to the constructor of the Error
class to see more information in the console
src/App.tsx
Outdated
}) | ||
.catch((error) => { | ||
setErrorMessage(TodosError.ADD_ERROR_MESSAGE); | ||
throw Error(error.message); |
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.
See comment above.
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.
Now, if you update the title with only spaces, it will not be deleted, but will remain empty.
Also now, when there is only one item left, the inscription is displayed in the plural 1 items
:
https://gyazo.com/da8bbe584d9275ad69b48843c104f688
src/App.tsx
Outdated
.then(setTodos) | ||
.catch((error) => { | ||
setErrorMessage(TodosError.DOWNLOAD_ERROR_MESSAGE); | ||
throw Error(error.message); |
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.
We can pass a pure error to the constructor of the Error
class to see more information in the console
src/App.tsx
Outdated
.then(() => { | ||
setTodoTitle(''); | ||
}) | ||
.catch(); |
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 catch
block, we must work with the error and not leave it empty
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 👍
const timerIdRef = useRef<number>(0); | ||
|
||
useEffect(() => { | ||
timerIdRef.current = window.setTimeout(() => { | ||
setErrorMessage(''); | ||
}, 3000); | ||
|
||
return () => clearTimeout(timerIdRef.current); | ||
}, [errorMessage]); |
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 keep related logic in the ErrorNotification
component
{todosSortBy === TodosSortType.All | ||
? `${todosLength - completedTodosLength} items left` | ||
: `${todosLength} 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.
It is better to put the number calculation in a separate variable for better readability.
Don't forget about all comments
DEMO LINK