-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Solution #2931
base: master
Are you sure you want to change the base?
Solution #2931
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.
Thank you for your hard work on this pull request! While your implementation is mostly solid, there are a few critical issues that need to be addressed before we can approve it. Specifically, the handling of the user
object and userId
in the NewTodo
component needs attention to ensure that the user
field is correctly populated with the full user object. Additionally, the getNewToDoId
function should be adjusted to handle cases where the todos
array is empty to prevent potential errors. Once these issues are resolved, your code will be in great shape! Keep up the good work! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/App.tsx
Outdated
})); | ||
|
||
function getNewToDoId(todos: ToDo[]) { | ||
const maxId = Math.max(...todos.map(todo => todo.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 Math.max
function will return -Infinity
if the todos
array is empty. Consider handling this case to avoid potential errors when the array is empty.
src/App.tsx
Outdated
const addToDo = (todo: Omit<ToDo, 'id'>) => { | ||
const newToDo = { | ||
...todo, | ||
id: getNewToDoId(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.
Ensure that the user
object is correctly populated when adding a new TODO. The user
field should contain the full user object, not just the userId
.
src/components/NewTodo/NewTodo.tsx
Outdated
onAdd({ | ||
title, | ||
userId, | ||
user: getUserById(userId), |
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.
Ensure that the user
field is correctly populated with the user object. The current implementation uses getUserById(userId)
, which should return the full user object. Verify that this function works as expected.
src/components/NewTodo/NewTodo.tsx
Outdated
setHasTitleError(!title); | ||
setHasUserIdError(!userId); | ||
|
||
if (!title || !userId) { |
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 userId
is initially set to 0
, which might not correspond to a valid user. Ensure that the userId
is set to a valid user ID before submission to avoid errors.
> | ||
<h2 className="TodoInfo__title">{todo.title}</h2> | ||
|
||
{todo.user && <UserInfo user={todo.user} />} |
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.
Ensure that todo.user
is always populated to avoid rendering issues with the UserInfo
component. If todo.user
can be undefined, consider adding a fallback or a conditional check.
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: 7]
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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.
Great job on your implementation! 🎉 Your code is mostly correct and meets the task requirements. Here are some important points to address:
- Typo: Correct the typo in
initiaTodos
toinitialTodos
for clarity. highestId
Calculation: Ensure it handles an emptytodos
array to avoid errors.userId
Field: ChangeuserId: number | null;
touserId: number;
since it's always set.foundUser
Check: Add a check to ensurefoundUser
is not null before accessing its properties.
These improvements will enhance your code's robustness. Keep up the good work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
Leanne Graham | ||
</a> | ||
</article> | ||
const initiaTodos: ToDo[] = todosFromServer.map(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.
There is a typo in the variable name initiaTodos
. It should be initialTodos
to reflect its purpose as the initial state for todos.
Leanne Graham | ||
</a> | ||
</article> | ||
const highestId = Math.max(...todos.map(todo => todo.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 calculation of highestId
should handle the case where the todos
array is empty. Consider using a default value or a conditional check to prevent errors when Math.max
is called with an empty array.
id: number; | ||
title: string; | ||
completed: boolean; | ||
userId: number | 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.
The userId
field in the ToDo
type should not be nullable because it is always set when a user is selected. Consider changing userId: number | null;
to userId: number;
.
userId: foundUser && foundUser.id, | ||
user: foundUser, |
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.
Ensure that foundUser
is not null before using its properties. You might want to add a check or handle the case where foundUser
is null to prevent potential runtime errors.
id: number; | ||
title: string; | ||
completed: boolean; | ||
userId: number | 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.
The userId
field in the ToDo
type should not be nullable because it is always set when a user is selected. Consider changing userId: number | null;
to userId: number;
.
DEMO LINK