-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: master
Are you sure you want to change the base?
Implement_a_TODO_app #717
Conversation
rialleons
commented
Oct 5, 2023
- DEMO LINK
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/components/Footer/Footer.scss
Outdated
@@ -0,0 +1,53 @@ | |||
.footer { | |||
color: #777; |
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 a good practice to make all colors variable
src/components/Header/Header.tsx
Outdated
} | ||
|
||
if (event.key === 'Enter') { | ||
if (newTodoTitle.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 (newTodoTitle.trim().length !== 0) { | |
if (newTodoTitle.trim().length) { |
src/components/Main/Main.tsx
Outdated
const dispatch = useContext(DispatchContext); | ||
const filterStatus = useContext(FilterContext); | ||
|
||
const [checked, setChecked] = useState(false); |
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.
Rename boolean variable according tips. Fix all cases if present
const [checked, setChecked] = useState(false); | |
const [isChecked, setIsChecked] = useState(false); |
src/components/TodoItem/TodoItem.tsx
Outdated
import React, { | ||
useContext, useRef, useState, useEffect, | ||
} from 'react'; |
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.
import React, { | |
useContext, useRef, useState, useEffect, | |
} from 'react'; | |
import React, { | |
useContext, | |
useRef, | |
useState, | |
useEffect, | |
} from 'react'; |
src/utils/manageLocalState.ts
Outdated
export const getStartingState = (): Todo[] => { | ||
const data = localStorage.getItem(key); | ||
|
||
if (data === null) { |
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 (data === null) { | |
if (!data) { |
src/components/Footer/Footer.tsx
Outdated
) : ( | ||
`${notCompletedLength} items left` | ||
)} | ||
{} |
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.
looks redundant
src/components/Main/Main.tsx
Outdated
break; | ||
|
||
case Status.Active: | ||
filteredTodos = [...todos].filter(todo => !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.
filteredTodos = [...todos].filter(todo => !todo.completed); | |
filteredTodos = todos.filter(todo => !todo.completed); |
filter doesn't change the array, so this copy is redundant
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 👍
Let's improve your code
src/components/Footer/Footer.scss
Outdated
@media (max-width: 430px) { | ||
& { | ||
height: 50px; | ||
} | ||
} |
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.
@media (max-width: 430px) { | |
& { | |
height: 50px; | |
} | |
} | |
@media (max-width: 430px) { | |
height: 50px; | |
} |
src/components/Footer/Footer.scss
Outdated
& strong { | ||
font-weight: 300; | ||
} |
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.
& strong { | |
font-weight: 300; | |
} | |
strong { | |
font-weight: 300; | |
} |
src/components/Footer/Footer.tsx
Outdated
{notCompletedLength === 1 ? ( | ||
'1 item left' | ||
) : ( | ||
`${notCompletedLength} items left` | ||
)} |
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 can move it to the helper function and use it here
src/components/Main/Main.scss
Outdated
& { | ||
background: none; | ||
} |
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 as above, need to fix it everywhere
& { | |
background: none; | |
} | |
background: none; |
<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> |
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.
Do you need so many providers?
You can create only 1 provider and pass an object with data to its value
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.
Do not forget check my comments
src/components/Main/Main.tsx
Outdated
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!'); | ||
} |
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.
My assumption is move this logic into helper function to get visible todos it will make your component cleaner
const visibleTodos = getVisibleTodos(todos, currentFilter);
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> |
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.
Also recomendation do not use anonymous function in JSX
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> |