Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #2931

wants to merge 2 commits into from

Conversation

AnnaAAA3432
Copy link

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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));

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),

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.

onAdd({
title,
userId,
user: getUserById(userId),

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.

setHasTitleError(!title);
setHasUserIdError(!userId);

if (!title || !userId) {

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} />}

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 to initialTodos for clarity.
  • highestId Calculation: Ensure it handles an empty todos array to avoid errors.
  • userId Field: Change userId: number | null; to userId: number; since it's always set.
  • foundUser Check: Add a check to ensure foundUser 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 => ({

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));

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;

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;.

Comment on lines +60 to +61
userId: foundUser && foundUser.id,
user: foundUser,

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;

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;.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants