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

add task solution #1051

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

Conversation

AndriiZakharenko
Copy link

Copy link

@ArturErmolenko ArturErmolenko left a comment

Choose a reason for hiding this comment

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

Well done 👍
Left comments but they no critical

const { todos, dispatch, handleFilterBy, filteredBy, originalTodos } =
useContext(TodoContext);

const activeTodos = originalTodos.filter(

Choose a reason for hiding this comment

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

Suggested change
const activeTodos = originalTodos.filter(
const activeTodosCount = originalTodos.filter(

const activeTodos = originalTodos.filter(
todo => todo.completed === false,
).length;
const disabled = todos.some(todo => todo.completed);

Choose a reason for hiding this comment

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

Suggested change
const disabled = todos.some(todo => todo.completed);
const isDisabled = todos.some(todo => todo.completed);

Comment on lines 31 to 70
<nav className="filter" data-cy="Filter">
<a
href="#/"
className={cn('filter__link', {
selected: filteredBy === FilterBy.All,
})}
data-cy="FilterLinkAll"
onClick={(event: React.MouseEvent<HTMLAnchorElement>) =>
handleFilter(event, FilterBy.All)
}
>
All
</a>

<a
href="#/active"
className={cn('filter__link', {
selected: filteredBy === FilterBy.Active,
})}
data-cy="FilterLinkActive"
onClick={(event: React.MouseEvent<HTMLAnchorElement>) =>
handleFilter(event, FilterBy.Active)
}
>
Active
</a>

<a
href="#/completed"
className={cn('filter__link', {
selected: filteredBy === FilterBy.Completed,
})}
data-cy="FilterLinkCompleted"
onClick={(event: React.MouseEvent<HTMLAnchorElement>) =>
handleFilter(event, FilterBy.Completed)
}
>
Completed
</a>
</nav>

Choose a reason for hiding this comment

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

To make your code cleaner you could use map + Object.values(FilterBy)

}

const newTodo: Todo = {
id: +new Date(),

Choose a reason for hiding this comment

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

lol)

dispatch({ type: ActionNames.Add, payload: newTodo });
};

const completed =

Choose a reason for hiding this comment

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

Suggested change
const completed =
const isCompleted =

const completed =
todos.length && todos.some(todo => todo.completed === false);

const allCompleted = originalTodos.every(todo => todo.completed);

Choose a reason for hiding this comment

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

Suggested change
const allCompleted = originalTodos.every(todo => todo.completed);
const isAllCompleted = originalTodos.every(todo => todo.completed);

setFilteredBy(type);
}, []);

const value = useMemo(

Choose a reason for hiding this comment

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

🔥

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.

2 participants