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

reactMoviesListAddFormCopy1 #2680

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

Conversation

SerhiiSemennikov
Copy link

No description provided.

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 you've made great progress, there are a few critical issues that need to be addressed to meet the task requirements:

  1. Validation on Blur: The NewMovie component should validate fields on blur to ensure all required fields are entered, which is currently not fully implemented.

  2. Disable Submit Button: The submit button should be disabled until all required fields are filled and trimmed, which is missing in the current implementation.

  3. Error Handling: Errors should not persist after clearing the form. The form should be reinitialized, which is not currently happening.

  4. getMaxId Function: This function is incorrectly implemented and may lead to errors in ID generation.

  5. Props Handling: Ensure NewMovie receives all required props correctly, as errorMessage and titleErrorMessage are currently passed as empty strings.

  6. 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];

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.

Comment on lines +24 to +28
<NewMovie
onAdd={addMovie}
movies={movies}
errorMessage={''}
titleErrorMessage={''}

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.

Comment on lines 27 to 29
<div className="media-content">
<p className="title is-8"></p>
</div>

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.

Comment on lines 13 to 15
function getMaxId(movies: Movie[]) {
return Math.max(...movies.map(m => movies.indexOf(m)));
}

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.

Comment on lines 54 to 56
//if (!title || !imdbUrl || !imgUrl) {
// return;
//}

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.

Comment on lines +69 to +71
if (!title || !imdbUrl || !imgUrl || title.length < 5) {
return;
}

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}

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}

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)}

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.

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 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:

  1. Validation on Blur: The NewMovie component should validate fields like title, imgUrl, imdbUrl, and imdbId when they lose focus. Make sure to implement this to enhance user experience.

  2. Disable Submit Button: Ensure the submit button is disabled until all required fields are filled and trimmed. This will prevent incomplete form submissions.

  3. Error Handling: Errors should not persist after clearing the form. Reinitialize the form correctly to clear any lingering errors.

  4. getMaxId Function: The current implementation is incorrect. It should return the maximum imdbId or another unique identifier, not the index of the movie. Consider using a property that uniquely identifies each movie.

  5. Props Handling: The errorMessage and titleErrorMessage props are currently passed as empty strings. Ensure these are managed internally within the NewMovie component based on validation logic.

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

Comment on lines +26 to +27
errorMessage={''}
titleErrorMessage={''}

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)));

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);

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.

Comment on lines +69 to +71
if (!title || !imdbUrl || !imgUrl || title.length < 5) {
return;
}

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.

Comment on lines +25 to +26
const [errorMessage, setErrorMessage] = useState('');
const [titleErrorMessage, setTitleErrorMessage] = useState('');

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)}

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.

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