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

solution #2131

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

solution #2131

wants to merge 5 commits into from

Conversation

Mariana-VV
Copy link

@Mariana-VV Mariana-VV commented Jan 29, 2024

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.

i can create the movie only with spaces, let's fix that
image

Comment on lines 14 to 18
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

@Mariana-VV Mariana-VV requested a review from etojeDenys January 29, 2024 18:45
Copy link

@anastasiia-tilikina anastasiia-tilikina left a comment

Choose a reason for hiding this comment

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

In order to fix your bug you should add name attr for your input in TextField component:
image

You forgot to do that)
Next time please ask for help in chat before sending your task for review. You'll get help faster

Comment on lines +14 to +20
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 this obj to a variable, let's say InitialValues to be able to reuse it, for example in reset method

Choose a reason for hiding this comment

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

isn't fixed. Create a variable outside the component and reuse it

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

imdbId: '',
});

const ifAllFieldsFilled = newMovie.title.trim() && newMovie.imgUrl.trim()

Choose a reason for hiding this comment

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

let's rename this var to something like isAllFieldsFilled
And read this article about naming boolean variables)

@@ -23,6 +23,7 @@ export const TextField: React.FC<Props> = ({
placeholder = `Enter ${label}`,
required = false,
onChange = () => {},
// isValidUrl = () => {},

Choose a reason for hiding this comment

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

remove commented code

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.

Approved)
Yet please apply that recommendation Anastasiia asked

Comment on lines +14 to +20
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.

isn't fixed. Create a variable outside the component and reuse it

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

Comment on lines +32 to +38
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(initialMovieState);

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