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

dev #783

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

dev #783

wants to merge 6 commits into from

Conversation

nikkias
Copy link

@nikkias nikkias commented Nov 18, 2023

Copy link

@volodymyr-soltys97 volodymyr-soltys97 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 👍
Let's improve your code

src/App.tsx Outdated
const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
if (query.trim()) {
setTodos([...todos, { id: Date.now(), title: query, completed: false }]);

Choose a reason for hiding this comment

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

Suggested change
setTodos([...todos, { id: Date.now(), title: query, completed: false }]);
const todo = {
id: Date.now(),
title: query,
completed: false,
};
setTodos([...todos, todo]);

<a href="#/completed">Completed</a>
</li>
</ul>
<TodosContext.Provider

Choose a reason for hiding this comment

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

Move provider to the context file, it will be a good practice

<ul className="todo-list" data-cy="todosList">
{todos.filter((todo) => {
switch (todosFilter) {
case 'Active':

Choose a reason for hiding this comment

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

Use a enum for these words
image

Comment on lines 13 to 22
{todos.filter((todo) => {
switch (todosFilter) {
case 'Active':
return !todo.completed;
case 'Completed':
return todo.completed;
default:
return true;
}
}).map((todo) => (

Choose a reason for hiding this comment

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

Move this logic from the jsx to the helper function and use it here

src/App.tsx Outdated
completed: false,
};

setTodos([...todos, todo]);

Choose a reason for hiding this comment

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

Suggested change
setTodos([...todos, todo]);
setTodos(prevTodos => [...prevTodos, todo]);

It is safer to pass updater callback when new state values depends on previous one

Comment on lines 18 to 20
setTodos(todos.map(todo => {
return { ...todo, completed: !isCompleted };
}));

Choose a reason for hiding this comment

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

same here pass callback

Comment on lines 18 to 20
const isCompleted = todos.some(todo => todo.completed);

const todosLeft = todos.filter(todo => todo.completed === false).length;

Choose a reason for hiding this comment

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

Suggested change
const isCompleted = todos.some(todo => todo.completed);
const todosLeft = todos.filter(todo => todo.completed === false).length;
const isCompleted = todos.some(todo => todo.completed);
const todosLeft = todos.filter(todo => !todo.completed).length;

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Almost done!
Let's improve your code

Comment on lines 66 to 70
case 'Escape':
resetChange();

break;
case 'Enter':

Choose a reason for hiding this comment

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

Suggested change
case 'Escape':
resetChange();
break;
case 'Enter':
case 'Escape':
resetChange();
break;
case 'Enter':

Comment on lines 79 to 82
saveChange();

break;
default:

Choose a reason for hiding this comment

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

Suggested change
saveChange();
break;
default:
saveChange();
break;
default:


return (
<ul className="todo-list" data-cy="todosList">
{filterTodos(todos, todosFilter).map((todo) => (

Choose a reason for hiding this comment

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

Consider will be better if you create a variable for this checking and use it here filterTodos(todos, todosFilter)

Suggested change
{filterTodos(todos, todosFilter).map((todo) => (
{filterTodos(todos, todosFilter).map((todo) => (

Comment on lines 10 to 12
if (data === null) {
return startValue;
}

Choose a reason for hiding this comment

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

Suggested change
if (data === null) {
return startValue;
}
if (!data) {
return startValue;
}

Comment on lines 19 to 26
setTodos((prevTodos: Todo[]) => {
const updatedTodos = prevTodos.map(todo => ({
...todo,
completed: !isCompleted,
}));

return updatedTodos;
});

Choose a reason for hiding this comment

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

Suggested change
setTodos((prevTodos: Todo[]) => {
const updatedTodos = prevTodos.map(todo => ({
...todo,
completed: !isCompleted,
}));
return updatedTodos;
});
setTodos((prevTodos: Todo[]) => prevTodos.map(todo => ({
...todo,
completed: !isCompleted,
}));
);

Comment on lines 66 to 70
case 'Escape':
resetChange();
break;

case 'Enter':

Choose a reason for hiding this comment

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

Please move Enter and Escape to the enum as it will make a code cleaner

Copy link

@loralevitska loralevitska left a comment

Choose a reason for hiding this comment

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

Almost perfect) Let's improve

  • remove todo if user remove text from todo by editing
    image

@nikkias nikkias requested a review from loralevitska November 20, 2023 18:09
Copy link

@andriy-shymkiv andriy-shymkiv 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 🔥

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.

7 participants