-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
need help #858
base: master
Are you sure you want to change the base?
need help #858
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.
Good start! Keep it up :)
Ask for help in your fe_chat
and try to find a solution
then request review on github(only when you solve issues, because it's hard to contact on github, mentors can see your comments only after your task appears in queue).
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.
I see you did a hard work) Let's improve it a little bit
todos: [], | ||
setTodos: () => {}, | ||
errorMessage: '', | ||
setErrorMessage: () => {}, | ||
preparedTodos: [], | ||
sortQuery: '', | ||
setSortQuery: () => {}, | ||
tempTodo: { | ||
id: 0, | ||
userId: 0, | ||
title: '', | ||
completed: false, | ||
}, | ||
setTempTodo: () => {}, | ||
todosInProcess: [], | ||
setTodosInProcess: () => {}, | ||
completedTodos: [], | ||
}); |
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.
try reducing the amount of props in the component, it's bad practice to have big amount of props
src/TodosContext/TodosContext.tsx
Outdated
const preparedTodos = todos?.filter(todo => { | ||
switch (sortQuery as SortType) { | ||
case SortType.Active: | ||
return todo.completed === 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.
return todo.completed === false; | |
return !todo.completed; |
src/TodosContext/TodosContext.tsx
Outdated
return todo.completed === false; | ||
|
||
case SortType.Completed: | ||
return todo.completed === true; |
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 todo.completed === true; | |
return todo.completed; |
src/TodosContext/TodosContext.tsx
Outdated
}) || todos; | ||
|
||
const completedTodos = todos?.filter(todo => ( | ||
todo.completed !== 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.
todo.completed !== false | |
todo.completed |
{/* <br /> | ||
Unable to delete a todo | ||
<br /> | ||
Unable to update a 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.
what is the purpose of these commented blocks?
src/components/Footer.tsx
Outdated
} = useTodos(); | ||
|
||
const notCompletedTodosLength = todos?.filter(todo => ( | ||
todo.completed === 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.
todo.completed === false | |
!todo.completed |
src/components/Footer.tsx
Outdated
)).length; | ||
|
||
const completedTodos = todos?.filter(todo => ( | ||
todo.completed !== 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.
todo.completed !== false | |
todo.completed |
src/components/Header.tsx
Outdated
}; | ||
|
||
const toggleAllTodos = () => { | ||
if (activeTodos?.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 (activeTodos?.length === 0) { | |
if (!activeTodos?.length) { |
src/components/TodoItem.tsx
Outdated
onDoubleClick={() => { | ||
setNewTitle(newTitle.trim()); | ||
setIsEditing(true); | ||
}} |
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.
Pls move the function inside onDoubleClick
handler to a separate const and use as a callback here
src/components/TodoItem.tsx
Outdated
placeholder="Empty todo will be deleted" | ||
value={newTitle} | ||
onChange={(event) => setNewTitle(event.target.value)} | ||
onBlur={() => handleOnBlur()} |
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.
onBlur={() => handleOnBlur()} | |
onBlur={handleOnBlur} |
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.
Toggle all button works incorrect - it should make all uncompleted todos completed without additional requests, other way if all todos are completed - they should became active
https://github.com/mate-academy/react_todo-app-with-api/assets/61904995/d6c38594-5e40-4ef8-808e-9e4d458b2f5b
src/App.tsx
Outdated
|
||
<TodoList /> | ||
|
||
{/* Hide the footer if there are no todos */} |
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 redundant comments
src/App.tsx
Outdated
{/* Notification is shown in case of any error */} | ||
{/* Add the 'hidden' class to hide the message smoothly */} |
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
src/TodosContext/TodosContext.tsx
Outdated
const preparedTodos = todos?.filter(todo => { | ||
switch (sortQuery as SortType) { | ||
case SortType.Active: | ||
return !todo.completed; | ||
|
||
case SortType.Completed: | ||
return todo.completed; | ||
|
||
default: | ||
return true; | ||
} | ||
}) || todos; |
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.
No need to filter in case SortType is all
src/components/Footer.tsx
Outdated
type="button" | ||
className="todoapp__clear-completed" | ||
data-cy="ClearCompletedButton" | ||
onClick={() => clearCompleted()} |
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.
Will works same but less callbacks
onClick={() => clearCompleted()} | |
onClick={clearCompleted} |
src/components/Header.tsx
Outdated
useEffect(() => { | ||
if (inputRef.current) { | ||
inputRef.current.focus(); | ||
} | ||
}, [isInputDisabled, !todos?.length, todosInProcess]); |
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/Header.tsx
Outdated
onClick={() => toggleAllTodos()} | ||
/> | ||
)} | ||
|
||
{/* Add a todo on form submit */} | ||
<form | ||
onSubmit={(event) => addTodo(event)} | ||
> |
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.
onClick={() => toggleAllTodos()} | |
/> | |
)} | |
{/* Add a todo on form submit */} | |
<form | |
onSubmit={(event) => addTodo(event)} | |
> | |
onClick={toggleAllTodos} | |
/> | |
)} | |
{/* Add a todo on form submit */} | |
<form | |
onSubmit={addTodo} | |
> |
<span | ||
data-cy="TodoTitle" | ||
className="todo__title" | ||
onDoubleClick={() => onDoubleClick()} |
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.
onDoubleClick={() => onDoubleClick()} | |
onDoubleClick={onDoubleClick} |
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 good.
DEMO LINK