-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: master
Are you sure you want to change the base?
add task solution #2750
Conversation
There was a problem hiding this 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:
-
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)} />
. -
Redundant Checks: There are redundant checks in your code that can be optimized:
- In the
TextField
component, thehasErrorUrl
condition checks bothvalidate(value)
anderror
, but sinceerror
is already set based onvalidate(value)
, you can simplify this by just checkingerror
. - In the
NewMovie
component, theisFormValid()
check is performed twice in thehandleSubmit
function. The second check is unnecessary and can be removed to streamline the logic.
- In the
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
<NewMovie | ||
onAdd={movie => { | ||
return handleAddMovie(movie); | ||
}} |
There was a problem hiding this comment.
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.
src/components/NewMovie/NewMovie.tsx
Outdated
|
||
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); | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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`} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 thehandleSubmit
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 checkserror
based onvalidate(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! ✨
DEMO LINK