-
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
Develop #815
base: master
Are you sure you want to change the base?
Develop #815
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 👍
Left some suggestions. Also, let's split logic, don't store all logic in the App
component.
For example:
- filter logic in the filter component
- toggle all in header as the button in this component
- add new todo in the form component or in the header too
- and so on
The smaller your components, the easier it is to manage and support them.
src/App.tsx
Outdated
const timerId = useRef<number>(0); | ||
|
||
useEffect(() => { | ||
if (timerId.current) { | ||
window.clearTimeout(timerId.current); | ||
} | ||
|
||
timerId.current = window.setTimeout(() => { | ||
setErrorMessage(ErrorMessage.Default); | ||
}, 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.
Move this logic to ErrorNotification
component
src/App.tsx
Outdated
}); | ||
}; | ||
|
||
const handleUpdateTodo = async (todo: Todo, newTodoTitle: 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.
If you don't use await
there no sense to do your function async
src/App.tsx
Outdated
.updateTodo({ | ||
id: todo.id, | ||
title: newTodoTitle, | ||
userId: todo.userId, | ||
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.
.updateTodo({ | |
id: todo.id, | |
title: newTodoTitle, | |
userId: todo.userId, | |
completed: todo.completed, | |
}) | |
.updateTodo({ | |
...todo, | |
title: newTodoTitle, | |
}) |
src/App.tsx
Outdated
const handleDeleteAllCompletedTodos = () => { | ||
todos | ||
.filter((todo) => todo.completed) | ||
.forEach((todo) => handleDeleteTodo(todo.id)); | ||
}; |
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.
When you need to send a batch of requests it's better to create an array of requests and handle them with Promise.all
or Promise.allsettled
src/App.tsx
Outdated
if (!isAllCompleted) { | ||
todos | ||
.filter((todo) => !todo.completed) | ||
.forEach((todo) => handleCompletedChange(todo)); | ||
} | ||
|
||
if (isAllCompleted) { | ||
todos | ||
.filter((todo) => todo.completed) | ||
.forEach((todo) => handleCompletedChange(todo)); | ||
} |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
{`${todosCounter} 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.
Remove comments
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 comments
Don't leave unnecessary comments, remove all of them
.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.
Why is the catch
block empty? You should notify the user if any error occurred.
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 is the
catch
block empty? You should notify the user if any error occurred.
🤷♂️
todo: Todo, | ||
}; | ||
|
||
export const TempTodo: React.FC<Props> = ({ 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.
You have a TodoItem
component with the same design, use it.
As in your case if you have any design changes you have to keep in mind and change in two components.
await onTodoUpdate(todoTitle); | ||
setIsEditing(false); | ||
} catch (er) { | ||
console.error('catch 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.
You should notify the user in case of an error instead of console.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.
Not fixed 😢
src/utils/TodoFilter.ts
Outdated
export enum FilterLink { | ||
All = '', | ||
Active = 'active', | ||
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.
Let's move to the types
folder
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.
Let's move to the
types
folder
Not 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.
Some of the comments are without any fixes and replies, check them
src/App.tsx
Outdated
return todoService | ||
.addTodo(todoTitle) | ||
.then((newTodo) => { | ||
setTodos((prevTodos) => [...prevTodos, newTodo]); | ||
}) | ||
.catch((error) => { | ||
setErrorMessage(ErrorMessage.Add); | ||
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.
You don't need to return something from the handler and throw an error as you handle it on this step
src/App.tsx
Outdated
setErrorMessage(ErrorMessage.Update); | ||
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.
The same, and in all other places
src/App.tsx
Outdated
if (!isAllCompleted) { | ||
todos | ||
.filter((todo) => !todo.completed) | ||
.forEach((todo) => handleCompletedChange(todo)); | ||
} | ||
|
||
if (isAllCompleted) { | ||
todos | ||
.filter((todo) => todo.completed) | ||
.forEach((todo) => handleCompletedChange(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.
if (!isAllCompleted) { | |
todos | |
.filter((todo) => !todo.completed) | |
.forEach((todo) => handleCompletedChange(todo)); | |
} | |
if (isAllCompleted) { | |
todos | |
.filter((todo) => todo.completed) | |
.forEach((todo) => handleCompletedChange(todo)); | |
} | |
todos | |
.filter((todo) => todo.completed === isAllCompleted) | |
.forEach((todo) => handleCompletedChange(todo)); |
You can simplify in this case
{`${todosCounter} 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.
Remove comments
Don't leave unnecessary comments, remove all of them
.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.
Why is the
catch
block empty? You should notify the user if any error occurred.
🤷♂️
} catch (er) { | ||
// console.error('catch 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.
🤷♂️
src/utils/TodoFilter.ts
Outdated
export enum FilterLink { | ||
All = '', | ||
Active = 'active', | ||
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.
Let's move to the
types
folder
Not fixed
As for me, it's okay when all handler logic is in one file in this task. |
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
@@ -1,24 +1,190 @@ | |||
/* 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
.filter((todo) => todo.completed) | ||
.forEach((todo) => handleDeleteTodo(todo.id)); |
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 not necessary to go around the array twice, it is enough to move the filtering condition to the middle of the forEach
and go through the array once instead of twice
src/App.tsx
Outdated
return todos.filter(todo => !todo.completed).length; | ||
}, [todos]); | ||
|
||
const isAllCompleted = useMemo(() => { |
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 isAllCompleted = useMemo(() => { | |
const isAllTodosCompleted = useMemo(() => { |
src/App.tsx
Outdated
.filter((todo) => todo.completed === isAllCompleted) | ||
.forEach((todo) => handleCompletedChange(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.
It is not necessary to go around the array twice, it is enough to move the filtering condition to the middle of the forEach and go through the array once instead of twice
setErrorMessage, | ||
errorMessage, | ||
}) => { | ||
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); |
const onFormSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
if (todoTitle.trim().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.
if (todoTitle.trim().length === 0) { | |
if (!todoTitle.trim().length) { |
active: isAllCompleted, | ||
})} | ||
data-cy="ToggleAllButton" | ||
onClick={() => onToggleClick()} |
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={() => onToggleClick()} | |
onClick={onToggleClick} |
<form | ||
onSubmit={onFormSubmit} | ||
> |
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.
<form | |
onSubmit={onFormSubmit} | |
> | |
<form onSubmit={onFormSubmit}> |
await onTodoUpdate(todoTitle); | ||
setIsEditing(false); | ||
} catch (er) { | ||
console.error('catch 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.
Not fixed 😢
src/utils/TodoFilter.ts
Outdated
arr: Todo[], | ||
option: string, | ||
) { | ||
const todos = [...arr]; |
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.
The filter
method returns a copy of the array, so you don't have to do it manually
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 👍
DEMO LINK