-
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
v1.0 #672
base: master
Are you sure you want to change the base?
v1.0 #672
Conversation
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/TodoList.tsx
Outdated
if (todo.id === todoId) { | ||
return { ...todo, title }; | ||
// eslint-disable-next-line no-else-return | ||
} else { | ||
return todo; | ||
} |
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 (todo.id === todoId) { | |
return { ...todo, title }; | |
// eslint-disable-next-line no-else-return | |
} else { | |
return todo; | |
} | |
if (todo.id === todoId) { | |
return { ...todo, title }; | |
} | |
return todo; | |
src/Components/TodoList.tsx
Outdated
useEffect(() => { | ||
const savedTodos = JSON.parse(localStorage.getItem('todos') || '[]'); | ||
|
||
setTodos(savedTodos); | ||
}, []); |
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 cause you have your custom hook for localStorage
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.
public/src/App.tsx
Outdated
const [isLoading, setIsLoading] = useState(false); | ||
const [todos, setTodos] = useLocalStorage('todos', []); | ||
|
||
const addNewTodo = async () => { |
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 really need an async function here? Seems that you await nothing here 🤔
public/src/App.tsx
Outdated
</form> | ||
</header> | ||
|
||
{todos.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.
You can use logical operators as well
{todos.length > 0 && ( | |
{!!todos.length && ( |
public/src/Components/TodoList.tsx
Outdated
const updatedTodos = todos.map((todo) => { | ||
if (todo.id === todoId) { | ||
return { ...todo, title }; | ||
// eslint-disable-next-line no-else-return |
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.
Remove this disabling
public/src/Components/TodoList.tsx
Outdated
const updatedTodos = todos.map((todo) => { | ||
if (todo.id === id) { | ||
return { ...todo, completed: !completed }; | ||
// eslint-disable-next-line no-else-return |
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.
Same
|
||
import { TodoList } from './Components/TodoList'; | ||
import { Footer } from './Components/Footer'; | ||
import { Header } from './Components/Header'; |
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.
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 { TodoList } from './Components/TodoList'; | ||
import { Footer } from './Components/Footer'; | ||
import { Header } from './Components/Header'; |
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.
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.
Pay attention on my comments - it's bad practice use anonymous function in JSX - try to refactor
onChange={() => { | ||
const updatedTodos = todos.map((todo) => { | ||
if (todo.id === id) { | ||
return { ...todo, completed: !completed }; | ||
} | ||
|
||
return todo; | ||
}); | ||
|
||
setTodos(updatedTodos); | ||
}} |
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.
logic should be moved into separate handler instead on anonymous function in jsx.
Fix all similar cases
}; | ||
|
||
return ( | ||
<footer className="todoapp__footer"> | ||
<span className="todo-count"> | ||
{itemsLeftLength === 1 | ||
? '1 item left' | ||
: `${itemsLeftLength} items left`} | ||
</span> | ||
|
||
<nav className="filter"> | ||
{filterOptions.map((option) => { | ||
return ( | ||
<a | ||
key={option} | ||
href={`#/${option}`} | ||
className={classNames( | ||
'filter__link', | ||
{ selected: filterBy === option }, | ||
)} | ||
onClick={() => setFilterBy(option)} | ||
> | ||
{option} | ||
</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.
}; | |
return ( | |
<footer className="todoapp__footer"> | |
<span className="todo-count"> | |
{itemsLeftLength === 1 | |
? '1 item left' | |
: `${itemsLeftLength} items left`} | |
</span> | |
<nav className="filter"> | |
{filterOptions.map((option) => { | |
return ( | |
<a | |
key={option} | |
href={`#/${option}`} | |
className={classNames( | |
'filter__link', | |
{ selected: filterBy === option }, | |
)} | |
onClick={() => setFilterBy(option)} | |
> | |
{option} | |
</a> | |
}; | |
const onFilterSelect = (filter: FilterType) => () => { | |
setFilterBy(filter) | |
} | |
return ( | |
<footer className="todoapp__footer"> | |
<span className="todo-count"> | |
{itemsLeftLength === 1 | |
? '1 item left' | |
: `${itemsLeftLength} items left`} | |
</span> | |
<nav className="filter"> | |
{filterOptions.map((option) => { | |
return ( | |
<a | |
key={option} | |
href={`#/${option}`} | |
className={classNames( | |
'filter__link', | |
{ selected: filterBy === option }, | |
)} | |
onClick={onFilterSelect(option)} | |
> | |
{option} | |
</a> |
https://JOWISSA.github.io/react_todo-app/