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 #2923

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

solution #2923

wants to merge 3 commits into from

Conversation

AlenaLoik
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 project! 🚀 While your code is mostly well-implemented, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Data Preparation and Import Usage: The TodoInfo component directly imports usersFromServer, which violates the requirement to centralize data preparation in the App component. Please refactor this to pass the necessary data as props from the App component.

  2. New Todo ID Calculation: The current method of calculating the new todo ID using Math.max(...ids) + 1 can fail when the todos array is empty, resulting in an incorrect ID. Please handle the case where todos is empty to ensure correct ID assignment.

  3. userId State Initialization: Initializing userId to 0 can lead to form submission with an invalid user ID if the selection isn't changed. Consider initializing userId to a non-zero value or adding explicit handling for this case.

Addressing these issues will ensure the application functions correctly and meets the core requirements. Keep up the great work, and I look forward to seeing your improvements! 😊

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


// import usersFromServer from './api/users';
// import todosFromServer from './api/todos';

export const App = () => {
const [todos, setTodos] = useState(todosFromServer as Todo[]);
const [todoTitle, setTodoTitle] = useState('');
const [userId, setUserId] = useState(0);

Choose a reason for hiding this comment

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

The userId state is initialized to 0, which is also the value used for the disabled option in the user select dropdown. This means that if a user doesn't change the selection, the form will submit with userId as 0, which might not be valid. Consider initializing userId to a non-zero value or handling this case explicitly.

src/App.tsx Outdated
const ids = todos.map(el => el.id);

const newTodo = {
id: Math.max(...ids) + 1,

Choose a reason for hiding this comment

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

The calculation of the new todo ID using Math.max(...ids) + 1 assumes that there is at least one todo in the list. If the todos array is empty, this will result in Math.max(...ids) being -Infinity, which will cause an incorrect ID. Consider handling the case where todos is empty separately.

export const TodoInfo: React.FC<Props> = ({ todo }) => {
const { id, title, completed, userId } = todo;

const user = usersFromServer.find(el => el.id === userId);

Choose a reason for hiding this comment

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

The user object is retrieved using find, which may return undefined if no user with the matching userId is found. Although this is checked in the JSX with {user && <UserInfo user={user} />}, it's good practice to handle the case where user is undefined more explicitly, possibly with a fallback message or a warning log.

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 effort on the implementation! 🎉 While the Pull Request is approved to help you move forward with your learning, there are a few critical issues that need attention:

  1. Data Preparation: Ensure that usersFromServer is not directly imported and used in components like TodoInfo. Instead, centralize data preparation in the App component and pass the necessary data as props to child components.

  2. New Todo ID Calculation: The current method of calculating a new todo ID using Math.max(...ids) + 1 may fail when the todos array is empty. Make sure to handle this scenario to ensure correct ID assignment, starting from 1 if necessary.

  3. User ID Initialization: Initializing userId to 0 can lead to form submission with an invalid user ID. Consider initializing it to a non-zero value or explicitly handling this case to prevent potential issues.

These improvements are crucial for the functionality and adherence to task requirements. Keep up the good work, and make sure to address these points in future iterations to enhance your code quality and learning experience. 🚀

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

import './App.scss';
import todosFromServer from './api/todos';
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.

The usersFromServer should not be directly imported and used here. According to the task requirements, data preparation should be centralized in the App component, and then passed as props to child components.


// import usersFromServer from './api/users';
// import todosFromServer from './api/todos';

export const App = () => {
const [todos, setTodos] = useState(todosFromServer as Todo[]);
const [todoTitle, setTodoTitle] = useState('');
const [userId, setUserId] = useState(0);

Choose a reason for hiding this comment

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

Initializing userId to 0 can lead to form submission with an invalid user ID. Consider initializing userId to a non-zero value or adding explicit handling for this case.

src/App.tsx Show resolved Hide resolved
@@ -1 +1,25 @@
export const TodoInfo = () => {};
import { Todo } from '../../type/todo';
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.

The usersFromServer should not be directly imported and used here. According to the task requirements, data preparation should be centralized in the App component, and then passed as props to child components like TodoInfo.

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