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

add solution #2913

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

add solution #2913

wants to merge 2 commits into from

Conversation

clavigo
Copy link

@clavigo clavigo commented Jan 5, 2025

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 meets many of the task requirements, there are a couple of critical issues that need to be addressed before we can approve it:

  1. Data Handling in Non-root Components: The UserInfo component imports usersFromServer directly, which violates the guideline to prepare data in the App component and pass it to child components. This is an important best practice for maintaining a clean and scalable codebase. Please refactor your code to pass the necessary data from the App component.

  2. Variable Naming: In your event handlers, consider using more descriptive variable names instead of one-letter names like e. This will greatly enhance the readability and maintainability of your code.

Once these changes are made, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you have any questions. 🌟

✨ 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

const [todos, setTodos] = React.useState<Todo[]>(todosFromServer);

const handleTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {

Choose a reason for hiding this comment

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

Avoid using one-letter variable names like e for event handlers. Instead, use a more descriptive name such as event to improve code readability and maintainability. This aligns with the checklist item: "Don't use one-letter variable naming."

src/App.tsx Outdated
setTitleError(false);
};

const handleSelectChange = (e: React.ChangeEvent<HTMLSelectElement>) => {

Choose a reason for hiding this comment

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

Consider renaming the variable e to a more descriptive name like event in the handleSelectChange function. This will enhance code readability and is recommended by the checklist: "Don't use one-letter variable naming."

export const TodoInfo = () => {};
import React from 'react';
import cn from 'classnames';
import { UserInfo } from '../UserInfo';

Choose a reason for hiding this comment

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

According to the checklist, you should not use the import keyword in non-root components. Instead, prepare data in the App component and pass it to child components. Consider passing the necessary data for UserInfo from the App component to TodoInfo and then to UserInfo to adhere to this guideline.

@@ -1 +1,29 @@
export const UserInfo = () => {};
import React from 'react';
import usersFromServer from '../../api/users';

Choose a reason for hiding this comment

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

Avoid importing data directly in non-root components. Instead, prepare the data in the App component and pass it down to child components. This aligns with the checklist item: "Don't use the import keyword in non-root components. Prepare data in the App component and pass it to child components."

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 addressing the majority of the issues from the previous review! 🎉 Your code is well-structured and demonstrates a solid understanding of React components and TypeScript types. Here are a few points to consider for further improvement:

  1. Data Handling: Ensure that all data preparation is done in the App component and passed down to child components as props. This is crucial for maintaining a clean and manageable codebase.

  2. Variable Naming: Consider using more descriptive names for event handler variables in the Form component to enhance code readability.

  3. Error Handling: Make sure that error messages for titleError and selectError are correctly displayed when the form is submitted with invalid inputs.

  4. Initialization of select: Consider initializing select with null or undefined instead of 0 to better represent an unselected state, as 0 might be a valid user ID.

  5. Return Values in map: Returning undefined from the map function can lead to rendering issues. Consider returning null instead.

These improvements will help you write cleaner and more maintainable code. Keep up the great work, and continue to learn from these experiences! 🚀

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

const [title, setTitle] = React.useState('');
const [titleError, setTitleError] = React.useState(false);

const [select, setSelect] = React.useState(0);

Choose a reason for hiding this comment

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

Consider initializing select with null or undefined instead of 0 to better represent an unselected state, as 0 might be a valid user ID.

Comment on lines +41 to +42
setTitleError(!title);
setSelectError(!select);

Choose a reason for hiding this comment

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

The error state for titleError and selectError is set based on the current values of title and select. Ensure that the error messages are correctly displayed when the form is submitted with invalid inputs.

Comment on lines +44 to +46
if (!title || !select) {
return;
}

Choose a reason for hiding this comment

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

The condition if (!title || !select) checks for empty title or unselected user. Ensure that select is initialized to a value that accurately represents an unselected state, as mentioned earlier.

export const TodoList = () => {};
import React from 'react';
import { TodoInfo } from '../TodoInfo';
import { Todos } from '../../types/Todos';

Choose a reason for hiding this comment

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

Ensure that the Todos type correctly represents the props being passed to the TodoList component. It should include both todos and users arrays.

);

if (!user) {
return;

Choose a reason for hiding this comment

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

Returning undefined from the map function when no user is found can lead to issues. Consider returning null instead to avoid rendering issues.

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