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

Develop #2122

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

Develop #2122

wants to merge 6 commits into from

Conversation

AV1788
Copy link

@AV1788 AV1788 commented Jan 21, 2024

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

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

Great work!
A user can create a film with spaces only, consider fixing it

Comment on lines 13 to 17
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.

It's not advisable to generate such a large number of states when we only have one instance (movie).
It'd be much better to utilize a single state with an object inside.

  1. Create a variable outside the Component
const initialMovieState = {
  title: '',
  description: '',
  imgUrl: '',
  imdbUrl: '',
  imdbId: ''
}
  1. Use one state for movie fields
  2. Pass initialMovieState object when you invoke reset function
  3. Whenever you need to change value of any field you should pass two arguments (key, value) and then just change a value of a movie object by key. In this case you will reuse one handler instead of handlers for each input
    Example:
const handleInputChange = (key, value) => {
  setMovie(prevInputs => ({...prevInputs, [key]: value}))
}
  1. for reset function you will just pass initialMovieState
Suggested change
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [imgUrl, setImgUrl] = useState('');
const [imdbUrl, setImdbUrl] = useState('');
const [imdbId, setImdbId] = useState('');
const [movie, setMovie] = useState(initialMovieState);


const handleSubmit = (event:React.FormEvent) => {
event.preventDefault();
const trimmedTitle = title.trim()

Choose a reason for hiding this comment

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

still can send a form with spaces in fields
Screenshot 2024-01-22 at 23 08 35

@AV1788 AV1788 requested a review from Viktor-Kost January 23, 2024 22:37
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