-
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 #2111
base: master
Are you sure you want to change the base?
add task solution #2111
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.
Good work! It`s great that you made advanced validation!
src/components/NewMovie/NewMovie.tsx
Outdated
movie: { | ||
title: string, | ||
description: string, | ||
imgUrl: string, | ||
imdbUrl: string, | ||
imdbId: string, | ||
} |
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 create type State and can use it as type for movie. Actually we already have the same type in 'types' folder, so you may use it instead of creating you own.
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.
agree)
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.
Nice! Validation is working! I like it!🤗
src/components/NewMovie/NewMovie.tsx
Outdated
disabled={!title | ||
|| !urlValidator(imgUrl) | ||
|| !urlValidator(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.
maybe put this check in const
@@ -23,6 +24,7 @@ export const TextField: React.FC<Props> = ({ | |||
placeholder = `Enter ${label}`, | |||
required = false, | |||
onChange = () => {}, | |||
checkUrl = undefined, |
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.
please don't write undefined
as a default value
you have already done this by adding ?
here:
checkUrl?: (urlString: string) => boolean,
src/components/NewMovie/NewMovie.tsx
Outdated
movie: { | ||
title: string, | ||
description: string, | ||
imgUrl: string, | ||
imdbUrl: string, | ||
imdbId: string, | ||
} |
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.
agree)
src/components/NewMovie/NewMovie.tsx
Outdated
setDescription(''); | ||
setImgUrl(''); | ||
setImdbUrl(''); | ||
setImdbId(''); |
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 can create a reset
function for this
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 the changes!
Let's do the last one☘️
src/components/NewMovie/NewMovie.tsx
Outdated
imdbUrl: string, | ||
imdbId: string, | ||
} | ||
) => void |
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.
If you don't understand what Oleksandr meant, then look at this
onAdd: (movie: Movie) => void
you already have Movie type
dont write
onAdd: (
movie: {
title: string,
description: string,
imgUrl: string,
imdbUrl: string,
imdbId: string,
}
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.
i fixed only in App. here I scroll and missed it))
src/components/NewMovie/NewMovie.tsx
Outdated
const [imdbId, setImdbId] = useState(''); | ||
|
||
const urlValidator = (urlString: string): boolean => { | ||
// eslint-disable-next-line max-len |
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.
put this function inside utils
folder
src/components/NewMovie/NewMovie.tsx
Outdated
= !title | ||
|| !urlValidator(imgUrl) | ||
|| !urlValidator(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.
try to fix code formatting
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.
Good job!
Approved with small comments.
Many thanks.
@@ -55,6 +57,8 @@ export const TextField: React.FC<Props> = ({ | |||
{hasError && ( | |||
<p className="help is-danger">{`${label} is required`}</p> | |||
)} | |||
|
|||
{((touched && value) && (checkUrl && !checkUrl(value))) && (<p className="help is-danger">{`${label} incorrect URL`}</p>)} |
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 can write this condition in constant ( too long )
DEMO LINK