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 task solution #2750

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

add task solution #2750

wants to merge 2 commits into from

Conversation

luchali
Copy link

@luchali luchali commented Feb 10, 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 is mostly correct and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Critical Syntax Error: The NewMovie component is missing the closing tag for the opening <NewMovie> element. This is a syntax error that will prevent the component from rendering correctly. Please update it to <NewMovie onAdd={movie => handleAddMovie(movie)} />.

  2. Redundant Checks: There are redundant checks in your code that can be optimized:

    • In the TextField component, the hasErrorUrl condition checks both validate(value) and error, but since error is already set based on validate(value), you can simplify this by just checking error.
    • In the NewMovie component, the isFormValid() check is performed twice in the handleSubmit function. The second check is unnecessary and can be removed to streamline the logic.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and I look forward to seeing the updated version. 😊

✨ 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
Comment on lines 21 to 24
<NewMovie
onAdd={movie => {
return handleAddMovie(movie);
}}

Choose a reason for hiding this comment

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

The NewMovie component is missing the closing tag for the opening <NewMovie> element. It should be <NewMovie onAdd={movie => handleAddMovie(movie)} /> instead of splitting the tag across multiple lines. This is a syntax error and will cause the component not to render correctly.

Comment on lines 56 to 77

if (isFormValid()) {
const newMovie = {
title: formData.title,
description: formData.description,
imgUrl: formData.imgUrl,
imdbUrl: formData.imdbUrl,
imdbId: formData.imdbId,
};

onAdd(newMovie);

setFormData({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});
setIsSubmitted(false);
setCount(prev => prev + 1);
}

Choose a reason for hiding this comment

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

The isFormValid() check is performed twice in the handleSubmit function. The second check is redundant since the first check already returns if the form is not valid. You can remove the second if (isFormValid()) block and directly proceed with the logic inside it after the first check.

const hasError = touched && required && !value;
const hasErrorUrl = (touched || isSubmitted) && validate(value) && error;

Choose a reason for hiding this comment

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

The hasErrorUrl condition checks validate(value) and error, but error is already set based on validate(value). You can simplify this condition by just checking error instead of calling validate(value) again.


{hasErrorUrl && (
<p className="help is-danger">
{validate(value) || `${label} is not well`}

Choose a reason for hiding this comment

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

Since error is already set based on validate(value) in the handleChange function, you can use error directly here instead of calling validate(value) again.

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 previous issues in your code! 🎉 Your implementation now meets the task requirements and constraints. Here are some key points from the review:

  • NewMovie Component: You've corrected the syntax error and streamlined the logic by removing the redundant isFormValid() check in the handleSubmit function. The component now properly verifies that required fields are filled out and disables the submit button until all required fields are completed. Additionally, the form is cleared after adding a new movie, and errors are not shown post-clearance.

  • TextField Component: The redundant checks have been optimized, and the hasErrorUrl condition now efficiently checks error based on validate(value).

While the code aligns well with the task requirements, remember to review the comments to further improve your code. Addressing any critical issues in the future will help you avoid similar problems and enhance your learning experience. Keep up the great work and continue to learn from your mistakes! 🚀

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

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.

3 participants