-
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
solution react_movies_list_add_form task #1909
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.
AWESOME!
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.
Almost perfect!
src/components/NewMovie/NewMovie.tsx
Outdated
const handleTitleUpdate = (newValue: string) => { | ||
setTitle(newValue); | ||
}; | ||
|
||
const handleDescriptionUpdate = (newValue: string) => { | ||
setDescription(newValue); | ||
}; | ||
|
||
const handleimgUrlUpdate = (newValue: string) => { | ||
setimgUrl(newValue); | ||
}; | ||
|
||
const handleImdbUrlUpdate = (newValue: string) => { | ||
setimdbUrl(newValue); | ||
}; | ||
|
||
const handleImdbIdUpdate = (newValue: string) => { | ||
setImdbId(newValue); | ||
}; |
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.
These functions are actually redundant
src/components/NewMovie/NewMovie.tsx
Outdated
value="" | ||
onChange={() => {}} | ||
value={title} | ||
onChange={handleTitleUpdate} |
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.
onChange={handleTitleUpdate} | |
onChange={setTitle} |
Can be simplified just like this
src/components/NewMovie/NewMovie.tsx
Outdated
> | ||
Add | ||
</button> | ||
{!title || !imgUrl || !imdbUrl || !imdbId ? ( |
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.
Create a variable for this condition
src/components/NewMovie/NewMovie.tsx
Outdated
type="submit" | ||
data-cy="submit-button" | ||
className="button is-link" | ||
disabled |
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.
disabled | |
disabled={condition} |
And just use it here. No need to render two different buttons
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, let's improve your code a bit more!
src/components/NewMovie/NewMovie.tsx
Outdated
|
||
/* eslint-disable max-len */ | ||
|
||
const pattern = /^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@,.\w_]*)#?(?:[,.!/\\\w]*))?)$/; |
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.
will be better move this into separated file like patterns
src/components/NewMovie/NewMovie.tsx
Outdated
incorrectimgUrl="" | ||
incorrectimdbUrl="" |
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.
let's remove these props with empty string
incorrectimgUrl, | ||
incorrectimdbUrl, |
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.
incorrectimgUrl, | |
incorrectimdbUrl, | |
incorrectimgUrl = '', | |
incorrectimdbUrl = '', |
}) => { | ||
// generage a unique id once on component load | ||
const [id] = useState(() => `${name}-${getRandomDigits()}`); | ||
|
||
// To show errors only if the field was touched (onBlur) | ||
// const pattern = /^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@,.\w_]*)#?(?:[,.!/\\\w]*))?)$/; |
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.
remove this comment
{hasError ? ( | ||
<p className="help is-danger">{`${label} is required`}</p> | ||
) : ( | ||
null | ||
)} |
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.
{hasError ? ( | |
<p className="help is-danger">{`${label} is required`}</p> | |
) : ( | |
null | |
)} | |
{hasError && ( | |
<p className="help is-danger">{`${label} is required`}</p> | |
)} |
can be simplify
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.
Well done! 🔥
onChange={(newValue) => { | ||
setTitle(newValue); | ||
}} |
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.
onChange={(newValue) => { | |
setTitle(newValue); | |
}} | |
onChange={setTitle} |
Can be simplified
setIncorrectimgUrl('Error'); | ||
setIncorrectimdbUrl('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 name of the state is a bit confusing. Also, you could set the full error's text here and use it to show the user instead of the "Label is not valid"
DEMO LINK