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

Implement_a_TODO_app #717

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

Conversation

rialleons
Copy link

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.

Good job! There are things that should be fixed:

  • add right condition for 1 item left
    image
  • remove outline, it breaks design

@@ -0,0 +1,53 @@
.footer {
color: #777;

Choose a reason for hiding this comment

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

It is a good practice to make all colors variable

}

if (event.key === 'Enter') {
if (newTodoTitle.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 (newTodoTitle.trim().length !== 0) {
if (newTodoTitle.trim().length) {

const dispatch = useContext(DispatchContext);
const filterStatus = useContext(FilterContext);

const [checked, setChecked] = useState(false);

Choose a reason for hiding this comment

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

Rename boolean variable according tips. Fix all cases if present

Suggested change
const [checked, setChecked] = useState(false);
const [isChecked, setIsChecked] = useState(false);

Comment on lines 2 to 4
import React, {
useContext, useRef, useState, useEffect,
} from 'react';

Choose a reason for hiding this comment

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

Suggested change
import React, {
useContext, useRef, useState, useEffect,
} from 'react';
import React, {
useContext,
useRef,
useState,
useEffect,
} from 'react';

export const getStartingState = (): Todo[] => {
const data = localStorage.getItem(key);

if (data === null) {

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) {
if (!data) {

@rialleons rialleons requested a review from loralevitska October 6, 2023 04:00
) : (
`${notCompletedLength} items left`
)}
{}

Choose a reason for hiding this comment

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

looks redundant

break;

case Status.Active:
filteredTodos = [...todos].filter(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
filteredTodos = [...todos].filter(todo => !todo.completed);
filteredTodos = todos.filter(todo => !todo.completed);

filter doesn't change the array, so this copy is redundant

@rialleons rialleons requested a review from etojeDenys October 6, 2023 08:25
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

Comment on lines 25 to 29
@media (max-width: 430px) {
& {
height: 50px;
}
}

Choose a reason for hiding this comment

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

Suggested change
@media (max-width: 430px) {
& {
height: 50px;
}
}
@media (max-width: 430px) {
height: 50px;
}

Comment on lines 36 to 38
& strong {
font-weight: 300;
}

Choose a reason for hiding this comment

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

Suggested change
& strong {
font-weight: 300;
}
strong {
font-weight: 300;
}

Comment on lines 25 to 29
{notCompletedLength === 1 ? (
'1 item left'
) : (
`${notCompletedLength} items left`
)}

Choose a reason for hiding this comment

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

You can move it to the helper function and use it here

Comment on lines 41 to 43
& {
background: none;
}

Choose a reason for hiding this comment

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

The same as above, need to fix it everywhere

Suggested change
& {
background: none;
}
background: none;

Comment on lines 31 to 39
<SetFilterContext.Provider value={setCurrentFilter}>
<FilterContext.Provider value={currentFilter}>
<DispatchContext.Provider value={dispatch}>
<StateContext.Provider value={todos}>
{children}
</StateContext.Provider>
</DispatchContext.Provider>
</FilterContext.Provider>
</SetFilterContext.Provider>

Choose a reason for hiding this comment

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

Do you need so many providers?
You can create only 1 provider and pass an object with data to its value

Copy link

@IvanFesenko IvanFesenko left a comment

Choose a reason for hiding this comment

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

Do not forget check my comments

Comment on lines 14 to 31
let filteredTodos: Todo[] = [];

switch (currentFilter) {
case Status.All:
filteredTodos = [...todos];
break;

case Status.Active:
filteredTodos = todos.filter(todo => !todo.completed);
break;

case Status.Completed:
filteredTodos = todos.filter(todo => todo.completed);
break;

default:
throw new Error('Unknown filter!');
}

Choose a reason for hiding this comment

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

My assumption is move this logic into helper function to get visible todos it will make your component cleaner
const visibleTodos = getVisibleTodos(todos, currentFilter);

Comment on lines 9 to 46
const { currentFilter, setCurrentFilter } = useContext(TodosContext);

return (
<ul className="filters" data-cy="todosFilter">
<li>
<a
href="#/"
className={classNames({
selected: currentFilter === Status.All,
})}
onClick={() => setCurrentFilter(Status.All)}
>
{Status.All}
</a>
</li>

<li>
<a
href="#/active"
className={classNames({
selected: currentFilter === Status.Active,
})}
onClick={() => setCurrentFilter(Status.Active)}
>
{Status.Active}
</a>
</li>

<li>
<a
href="#/completed"
className={classNames({
selected: currentFilter === Status.Completed,
})}
onClick={() => setCurrentFilter(Status.Completed)}
>
{Status.Completed}
</a>

Choose a reason for hiding this comment

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

Also recomendation do not use anonymous function in JSX

Suggested change
const { currentFilter, setCurrentFilter } = useContext(TodosContext);
return (
<ul className="filters" data-cy="todosFilter">
<li>
<a
href="#/"
className={classNames({
selected: currentFilter === Status.All,
})}
onClick={() => setCurrentFilter(Status.All)}
>
{Status.All}
</a>
</li>
<li>
<a
href="#/active"
className={classNames({
selected: currentFilter === Status.Active,
})}
onClick={() => setCurrentFilter(Status.Active)}
>
{Status.Active}
</a>
</li>
<li>
<a
href="#/completed"
className={classNames({
selected: currentFilter === Status.Completed,
})}
onClick={() => setCurrentFilter(Status.Completed)}
>
{Status.Completed}
</a>
const { currentFilter, setCurrentFilter } = useContext(TodosContext);
const onFilterSelect = (status: Status) => () => {
setCurrentFilter(status);
}
return (
<ul className="filters" data-cy="todosFilter">
<li>
<a
href="#/"
className={classNames({
selected: currentFilter === Status.All,
})}
onClick={onFilterSelect(Status.All)}
>
{Status.All}
</a>
</li>
<li>
<a
href="#/active"
className={classNames({
selected: currentFilter === Status.Active,
})}
onClick={onFilterSelect(Status.Active)}
>
{Status.Active}
</a>
</li>
<li>
<a
href="#/completed"
className={classNames({
selected: currentFilter === Status.Completed,
})}
onClick={onFilterSelect(Status.Completed)}
>
{Status.Completed}
</a>

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.

5 participants