Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Develop #815

wants to merge 5 commits into from

Conversation

Valentyn-Bilyk
Copy link

Copy link

@BudnikOleksii BudnikOleksii left a 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
Comment on lines 36 to 46
const timerId = useRef<number>(0);

useEffect(() => {
if (timerId.current) {
window.clearTimeout(timerId.current);
}

timerId.current = window.setTimeout(() => {
setErrorMessage(ErrorMessage.Default);
}, 3000);
}, [errorMessage]);

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) => {

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
Comment on lines 95 to 100
.updateTodo({
id: todo.id,
title: newTodoTitle,
userId: todo.userId,
completed: todo.completed,
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.updateTodo({
id: todo.id,
title: newTodoTitle,
userId: todo.userId,
completed: todo.completed,
})
.updateTodo({
...todo,
title: newTodoTitle,
})

src/App.tsx Outdated
Comment on lines 147 to 151
const handleDeleteAllCompletedTodos = () => {
todos
.filter((todo) => todo.completed)
.forEach((todo) => handleDeleteTodo(todo.id));
};

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
Comment on lines 166 to 176
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.

{`${todosCounter} items left`}
</span>

{/* Active filter should have a 'selected' class */}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments

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

Comment on lines 43 to 45
.catch(() => {

});

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.

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 }) => (

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');

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fixed 😢

Comment on lines 3 to 7
export enum FilterLink {
All = '',
Active = 'active',
Completed = 'completed',
}

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

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

Copy link

@BudnikOleksii BudnikOleksii left a 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
Comment on lines 44 to 51
return todoService
.addTodo(todoTitle)
.then((newTodo) => {
setTodos((prevTodos) => [...prevTodos, newTodo]);
})
.catch((error) => {
setErrorMessage(ErrorMessage.Add);
throw error;

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
Comment on lines 93 to 94
setErrorMessage(ErrorMessage.Update);
throw error;

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
Comment on lines 146 to 156
if (!isAllCompleted) {
todos
.filter((todo) => !todo.completed)
.forEach((todo) => handleCompletedChange(todo));
}

if (isAllCompleted) {
todos
.filter((todo) => todo.completed)
.forEach((todo) => handleCompletedChange(todo));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 */}

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

Comment on lines 43 to 45
.catch(() => {

});

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.

🤷‍♂️

Comment on lines 35 to 37
} catch (er) {
// console.error('catch error');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

Comment on lines 3 to 7
export enum FilterLink {
All = '',
Active = 'active',
Completed = 'completed',
}

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

@Valentyn-Bilyk
Copy link
Author

As for me, it's okay when all handler logic is in one file in this task.

Copy link

@roman-mirzoian roman-mirzoian left a 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 */

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
Comment on lines 102 to 103
.filter((todo) => todo.completed)
.forEach((todo) => handleDeleteTodo(todo.id));

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(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isAllCompleted = useMemo(() => {
const isAllTodosCompleted = useMemo(() => {

src/App.tsx Outdated
Comment on lines 143 to 144
.filter((todo) => todo.completed === isAllCompleted)
.forEach((todo) => handleCompletedChange(todo));

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const timerId = useRef<number>(0);
const timerIdRef = useRef<number>(0);

const onFormSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (todoTitle.trim().length === 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (todoTitle.trim().length === 0) {
if (!todoTitle.trim().length) {

active: isAllCompleted,
})}
data-cy="ToggleAllButton"
onClick={() => onToggleClick()}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onClick={() => onToggleClick()}
onClick={onToggleClick}

Comment on lines 65 to 67
<form
onSubmit={onFormSubmit}
>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<form
onSubmit={onFormSubmit}
>
<form onSubmit={onFormSubmit}>

await onTodoUpdate(todoTitle);
setIsEditing(false);
} catch (er) {
console.error('catch error');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fixed 😢

arr: Todo[],
option: string,
) {
const todos = [...arr];

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

Copy link

@BudnikOleksii BudnikOleksii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants