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

add task react_movies-list-add-form #2120

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

Conversation

P-Nazar
Copy link

@P-Nazar P-Nazar commented Jan 20, 2024

Comment on lines 21 to 25
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [imgUrl, setImgUrl] = useState('');
const [imdbUrl, setimdbUrl] = useState('');
const [imdbId, setImdbId] = useState('');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can combine it in one useState

const [newMovie, setNewMovie] = useState({
  title: '',
  ...
})

now we can also create only one handle function for all fields

const handleChange = (e: ...) => {
  const {name, value} = e.target;
  setMovie((prevMovie) => ({...prevMovie, [name]: value}))
}

don't forget to specify name attr to input in TextField

@P-Nazar P-Nazar requested a review from etojeDenys January 20, 2024 12:55
Copy link

@VitaliyBondarenko1982 VitaliyBondarenko1982 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done.
Please check a few comments.

label="Image URL"
value=""
value={newMovie.imgUrl}
onChange={e => handleChange(e)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onChange={e => handleChange(e)}
onChange={handleChange}

it will be the same

label="Imdb URL"
value=""
value={newMovie.imdbUrl}
onChange={e => handleChange(e)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onChange={e => handleChange(e)}
onChange={handleChange}

it will be the same

Comment on lines 124 to 127
disabled={!newMovie.title
|| !urlValidator(newMovie.imgUrl)
|| !urlValidator(newMovie.imdbUrl)
|| !newMovie.imdbId}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to move in constant.

const isDisabled = !newMovie.title.trim() || !urlValidator(newMovie.imgUrl) || !urlValidator(newMovie.imdbUrl) || !newMovie.imdbId.trim()
Suggested change
disabled={!newMovie.title
|| !urlValidator(newMovie.imgUrl)
|| !urlValidator(newMovie.imdbUrl)
|| !newMovie.imdbId}
disabled={isDisabled}

trim for other required values will solve such problem as on screencast
chrome-capture-2024-1-20

src/App.tsx Outdated

export const App = () => {
const [movieList, setMovieList] = useState<Movie[]>([...moviesFromServer]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [movieList, setMovieList] = useState<Movie[]>([...moviesFromServer]);
const [movieList, setMovieList] = useState<Movie[]>(moviesFromServer);

redundant to destructure

// const [description, setDescription] = useState('');
// const [imgUrl, setImgUrl] = useState('');
// const [imdbUrl, setimdbUrl] = useState('');
// const [imdbId, setImdbId] = useState('');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not keep commented code

@@ -47,14 +50,16 @@ export const TextField: React.FC<Props> = ({
})}
placeholder={placeholder}
value={value}
onChange={event => onChange(event.target.value)}
onChange={event => onChange(event)}
onBlur={() => setTouched(true)}
/>
</div>

{hasError && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim value in hasError counting for correct show error message when fill input only with empty spaces.
const hasError = touched && required && !value.trim();

Copy link

@Viktor-Kost Viktor-Kost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Some minor changes needed

imdbId: '',
});

const urlValidator = (urlString: string): boolean => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this helper outside the component

Comment on lines 5 to 13
onAdd: (
movie: {
title: string,
description: string,
imgUrl: string,
imdbUrl: string,
imdbId: string,
}
) => void
Copy link

@Viktor-Kost Viktor-Kost Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have a type for a movie

Suggested change
onAdd: (
movie: {
title: string,
description: string,
imgUrl: string,
imdbUrl: string,
imdbId: string,
}
) => void
onAdd: (
movie: (movie: Movie) => void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't fixed

Comment on lines 20 to 26
const [newMovie, setNewMovie] = useState({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move initial state to a variable initialMovieState (outside the component)

Suggested change
const [newMovie, setNewMovie] = useState({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});
const [newMovie, setNewMovie] = useState<Movie>(initialMovieState);

Comment on lines 54 to 60
setNewMovie({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setNewMovie({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});
setNewMovie(initialMovie);

@P-Nazar P-Nazar requested a review from Viktor-Kost January 22, 2024 21:05
Copy link

@Viktor-Kost Viktor-Kost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 5 to 13
onAdd: (
movie: {
title: string,
description: string,
imgUrl: string,
imdbUrl: string,
imdbId: string,
}
) => void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't fixed

@P-Nazar P-Nazar requested a review from Viktor-Kost January 23, 2024 19:39
Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.

4 participants