-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
reactMoviesListAddFormCopy1 #2680
base: master
Are you sure you want to change the base?
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 you've made great progress, there are a few critical issues that need to be addressed to meet the task requirements:
-
Validation on Blur: The
NewMovie
component should validate fields on blur to ensure all required fields are entered, which is currently not fully implemented. -
Disable Submit Button: The submit button should be disabled until all required fields are filled and trimmed, which is missing in the current implementation.
-
Error Handling: Errors should not persist after clearing the form. The form should be reinitialized, which is not currently happening.
-
getMaxId
Function: This function is incorrectly implemented and may lead to errors in ID generation. -
Props Handling: Ensure
NewMovie
receives all required props correctly, aserrorMessage
andtitleErrorMessage
are currently passed as empty strings. -
Code Cleanup: Remove unnecessary commented-out code and redundant checks to improve clarity and maintainability.
Please address these issues to ensure the functionality aligns with the task requirements. Keep up the great work, and don't hesitate to reach out if you need further guidance! 🚀
✨ 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
|
||
export const App = () => { | ||
const visibleMovies = [...moviesFromServer]; |
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.
You don't need to create a copy of the moviesFromServer
array using the spread operator here. According to the checklist, if you are using a non-mutating array method, you don't need to create a copy of the array. You can directly use moviesFromServer
.
<NewMovie | ||
onAdd={addMovie} | ||
movies={movies} | ||
errorMessage={''} | ||
titleErrorMessage={''} |
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.
Ensure that the NewMovie
component receives all required props correctly. Currently, errorMessage
and titleErrorMessage
are passed as empty strings. Verify if this is the intended behavior or if they should be dynamically set based on form validation results.
<div className="media-content"> | ||
<p className="title is-8"></p> | ||
</div> |
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 second media-content
div is empty and does not serve any purpose. It seems to be a leftover from a copy-paste operation. Consider removing it to clean up the code.
src/components/NewMovie/NewMovie.tsx
Outdated
function getMaxId(movies: Movie[]) { | ||
return Math.max(...movies.map(m => movies.indexOf(m))); | ||
} |
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 getMaxId
function is incorrectly implemented. It uses movies.indexOf(m)
which will always return the index of the first occurrence of m
, leading to incorrect ID generation. You should map to m.id
or a similar property if Movie
has an id
field.
src/components/NewMovie/NewMovie.tsx
Outdated
//if (!title || !imdbUrl || !imgUrl) { | ||
// return; | ||
//} |
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.
This block of code is commented out but seems to be a necessary validation check. Consider uncommenting and using it to ensure that all required fields are filled before submission.
if (!title || !imdbUrl || !imgUrl || title.length < 5) { | ||
return; | ||
} |
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.
This validation check is redundant because similar checks are already performed earlier. Consider removing this block to avoid unnecessary code.
required | ||
errorMessage={titleErrorMessage} |
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.
Ensure that titleErrorMessage
is correctly set based on the validation logic. Currently, it is only set when the title is missing or too short.
value={imgUrl} | ||
onChange={setImgUrl} | ||
required | ||
errorMessage={errorMessage} |
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 errorMessage
is used for both imgUrl
and imdbUrl
fields. Consider using separate error messages for each field to provide more specific feedback to the user.
@@ -49,8 +52,11 @@ export const TextField: React.FC<Props> = ({ | |||
onBlur={() => setTouched(true)} | |||
/> | |||
</div> | |||
|
|||
{errorMessage && (hasError = false)} |
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 line {errorMessage && (hasError = false)}
is problematic because it directly modifies the hasError
flag based on the presence of an errorMessage
. This can lead to incorrect error handling logic. Consider restructuring the logic to ensure hasError
is set correctly based on the intended conditions.
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 effort on your submission! 🎉 While your code has been approved to help you move forward with your learning, there are several critical areas that need improvement:
-
Validation on Blur: The
NewMovie
component should validate fields liketitle
,imgUrl
,imdbUrl
, andimdbId
when they lose focus. Make sure to implement this to enhance user experience. -
Disable Submit Button: Ensure the submit button is disabled until all required fields are filled and trimmed. This will prevent incomplete form submissions.
-
Error Handling: Errors should not persist after clearing the form. Reinitialize the form correctly to clear any lingering errors.
-
getMaxId
Function: The current implementation is incorrect. It should return the maximumimdbId
or another unique identifier, not the index of the movie. Consider using a property that uniquely identifies each movie. -
Props Handling: The
errorMessage
andtitleErrorMessage
props are currently passed as empty strings. Ensure these are managed internally within theNewMovie
component based on validation logic. -
Code Cleanup: Remove any commented-out code and redundant checks to improve clarity and maintainability.
Addressing these issues will not only align your code with the task requirements but also enhance its functionality and maintainability. Keep up the good work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
errorMessage={''} | ||
titleErrorMessage={''} |
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 errorMessage
and titleErrorMessage
props are currently passed as empty strings. Ensure these props are correctly handled and passed meaningful values, as per the task requirements.
titleErrorMessage: string; | ||
}; | ||
function getMaxId(movies: Movie[]) { | ||
return Math.max(...movies.map(movie => movies.indexOf(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 getMaxId
function is incorrectly implemented. It should return the maximum imdbId
or another unique identifier, not the index of the movie. Consider using a property of Movie
that uniquely identifies it.
} | ||
|
||
export const NewMovie: React.FC<Props> = ({ onAdd, movies }) => { | ||
const [count, setCount] = useState(getMaxId(movies) + 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 initial count is set using getMaxId
, which is incorrectly implemented. Ensure count
is initialized with a correct unique identifier.
if (!title || !imdbUrl || !imgUrl || title.length < 5) { | ||
return; | ||
} |
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 submit button should be disabled until all required fields are filled and trimmed. Currently, this logic is not implemented, allowing form submission even when fields are incomplete.
const [errorMessage, setErrorMessage] = useState(''); | ||
const [titleErrorMessage, setTitleErrorMessage] = useState(''); |
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.
Ensure that error messages are cleared when the form is reset. This will prevent errors from persisting after clearing the form.
@@ -49,8 +52,11 @@ export const TextField: React.FC<Props> = ({ | |||
onBlur={() => setTouched(true)} | |||
/> | |||
</div> | |||
|
|||
{errorMessage && (hasError = false)} |
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 logic here resets hasError
when errorMessage
is present. This can lead to unexpected behavior where the required field error is not shown even if the field is empty. Consider revising this logic to ensure both types of errors are handled correctly.
No description provided.