Skip to content

React-add-todo-form-Pronina#3564

Open
ProninaMariia wants to merge 3 commits intomate-academy:masterfrom
ProninaMariia:develop
Open

React-add-todo-form-Pronina#3564
ProninaMariia wants to merge 3 commits intomate-academy:masterfrom
ProninaMariia:develop

Conversation

@ProninaMariia
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.

Review Summary

This is a solid effort, but I'm requesting a few changes to fix some critical bugs. First, the logic for generating a new todo ID fails when the list is empty because Math.max() on an empty array returns -Infinity. This prevents the first todo from being added. Second, the User type is missing the username field, which is a core requirement. Finally, the type assertion as User is unsafe and will cause a runtime error if a user isn't found; please add a check to ensure a user exists before creating the todo. Addressing these points will make your solution robust and fully compliant.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/App.tsx Outdated
Comment on lines +6 to +10
type User = {
id: number;
name: string;
email: string;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The User type is missing the username field, which is explicitly required by the task description. The description states that the user object on a todo item should contain id, name, username, and email.

src/App.tsx Outdated
return;
}

const newId = Math.max(...todos.map(todo => todo.id)) + 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic for generating a new ID will fail if the todos array is empty. Math.max() with no arguments returns -Infinity, which will result in an invalid ID for the first todo item. Consider handling the empty array case, for example by providing a default starting value to Math.max.

src/App.tsx Outdated

const user = usersFromServer.find(
currentUser => currentUser.id === Number(userId),
) as User;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using as User is an unsafe type assertion. The find method can return undefined if no user matches the userId, which would cause a runtime error when user is used later. It's better to add a check to ensure user is not undefined before proceeding.

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.

Review Summary

Great job addressing the critical issues from the previous review! The application is much more robust now.

However, this requires a couple of changes because the build is currently failing due to a linting error, and there's a violation of a core principle.

  1. Build Failure: In src/App.tsx, you have a variable shadowing issue. The parameter in your .find() method is named user, which conflicts with the const user you declare just outside of it. Please rename the inner parameter to resolve this.
    const user = usersFromServer.find(
      u => u.id === todo.userId, // Rename 'user' to 'u' or something similar
    );
  2. Code Duplication: The User type is defined in both src/components/TodoInfo/TodoInfo.tsx and src/components/UserInfo/UserInfo.tsx. To follow the "Don't Repeat Yourself" principle [CHECKLIST ITEM #2], please move this type to a single shared file (like src/types.ts) and import it where needed.

Once these are fixed, your solution will be ready for approval. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/App.tsx Outdated

return {
...todo,
user: user!,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a non-null assertion (!) here can be risky. If a todo from the server has a userId that doesn't exist in usersFromServer, user will be undefined, and the app will crash when trying to access its properties. A safer approach is to filter out any todos that don't have a matching user, ensuring your application's data is always consistent.

Comment on lines +1 to +6
type User = {
id: number;
name: string;
username: string;
email: string;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The User type definition is repeated here and in TodoInfo.tsx. To adhere to the 'Don't Repeat Yourself' (DRY) principle, you should define this type in one central place (for example, in a types.ts file or exported from TodoInfo.tsx) and import it where needed. This violates checklist item #2: "Don't repeat yourself."

Comment on lines +3 to +8
type User = {
id: number;
name: string;
username: string;
email: string;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This User type is also defined in the UserInfo component. This violates checklist item #2: "Don't repeat yourself. If you see that you copy/paste some block code, maybe, it's time to create a separate variable/function". Consider creating a central types file (e.g., src/types.ts) to store shared type definitions like User and Todo, and then import them in the components that need them.

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.

Review Summary

Excellent work on this task! You've done a fantastic job addressing the previous feedback, especially by creating a centralized types.ts file, which greatly improves the code's maintainability. I am approving your solution so you can move forward, but there is one small style improvement to consider for future tasks.

In src/App.tsx, the variable u is used in a .find() callback. While this works, it's best to use more descriptive names like user to improve code readability, as mentioned in the project guidelines [CHECKLIST ITEM #1].

Overall, this is a very strong submission. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment on lines +12 to +13
const u = usersFromServer.find(
u => u.id === todo.userId,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #1: "Don't use one-letter variable naming." The variable u should have a more descriptive name, for example, user. This also applies to the parameter u in the .find() method on this line and on line 60.

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