-
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
solved task #1486
base: master
Are you sure you want to change the base?
solved task #1486
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.
Nice work, but you should consider code consistency. For example, if some logic is in the hook, it should all be there. I won't reject it, but I highly recommend you to pay attention to it.
And a lot of code duplication.
setLoadingTodosCount, | ||
setTodos, | ||
setInputValue, | ||
} = useTodos(setErrorMessage); |
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.
In my opinion, it's rather confusing. Part of the logic associated with todo is in the custom hook, and the other part is spread across components. It is better to either put everything in the hook or not use it at all.
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 point!
src/App.tsx
Outdated
|
||
Promise.all( | ||
todosForDeleting.map(id => | ||
deleteTodos(id) |
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'd rather think about how to avoid repeating the code. It uses the same logic as deleting a single element, so maybe you should think about how to reuse the already existing code?
This applies to deletion as well as any updates.
onSubmit, | ||
onInputChange, | ||
}) => { | ||
const isLoading = loadingTodos.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.
const isLoading = loadingTodos.length > 0; | |
!!loadingTodos.length |
src/components/TodoComponent.tsx
Outdated
onTodoDelete: (todoId: number) => void; | ||
onTodoToggle: (todoId: number, currentCompletedStatus: boolean) => void; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
onUpdateTodo: any; |
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.
onUpdateTodo: any; | |
onUpdateTodo: Promise<Todo>; |
Wouldn't that be better? Or Promise<unknown>
at least
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 solution
setLoadingTodosCount, | ||
setTodos, | ||
setInputValue, | ||
} = useTodos(setErrorMessage); |
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 point!
src/components/Footer.tsx
Outdated
return ( | ||
<footer className="todoapp__footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{todos.length - completedTodos.length} 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.
Create a variable for this calculation
src/components/TodoComponent.tsx
Outdated
if (isEditing && inputRef.current) { | ||
inputRef.current.focus(); | ||
} | ||
}, [isEditing, inputRef]); //? |
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.
Delete commented code
src/utils/updateTodo.ts
Outdated
? operation(id, { completed: newStatus }) | ||
: deleteOperation | ||
? deleteOperation(id) | ||
: operation(id); |
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 nested ternary operator can be hard to read. Consider refactoring that section for clarity.
src/App.tsx
Outdated
useEffect(() => { | ||
if (errorMessage) { | ||
const timer = setTimeout(() => { | ||
setErrorMessage(ErrorMessages.NO_ERRORS); | ||
}, 3000); | ||
|
||
return () => clearTimeout(timer); | ||
} | ||
}, [errorMessage]); |
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.
Move to error notification file
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.
2024-10-23.14.25.15.mov
Good job! Left fix few bugs. Watch video, I've showed input doesn't recive focus after adding new todo, but it has to.
Fix it and go forward to the next task!
P.s.: cool case to slove this task using custom hook! 🆒 😎
It's strange, that you have such behaviour, because from my side it works perfectly.🤨 |
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.
Completed! 🔥 🔥
DEMO LINK