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

task done #2101

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

task done #2101

wants to merge 4 commits into from

Conversation

Manankin
Copy link

Copy link

@vpashko vpashko left a comment

Choose a reason for hiding this comment

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

Good job! Keep going!

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('');
Copy link

Choose a reason for hiding this comment

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

you can use object with type Movie and create only one state for all fields.

const InitialFieldsOfMovie: Movie = {
  title: '',
  description: '',
  imgUrl: '',
  imdbUrl: '',
  imdbId: '',
};

// your code

const [fieldsOfMovie, setFieldsOfMovie] = React.useState(InitialFieldsOfMovie);

I think it's easier to use because you don't have to create a lot of states for each field, but your solution is also suitable (It is not necessary to change)

Copy link
Author

Choose a reason for hiding this comment

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

We ask about this our teacher Misha and he said that it is not better.

Copy link

@YegorKorenkov YegorKorenkov left a comment

Choose a reason for hiding this comment

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

Good job! Please check minor mistake and answer my question

const [imdbUrl, setImdbUrl] = useState('');
const [imdbId, setImdbId] = useState('');

const isAbleToAdd = title && imgUrl && imdbUrl && imdbId;

Choose a reason for hiding this comment

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

Don't forget to trim() value, because now I able to add "empty" movie
image

<form className="NewMovie" key={count}>
<form
className="NewMovie"
key={count}

Choose a reason for hiding this comment

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

Why you need to add this key attribute? Why you need to reset "touched status"? Can you explain please?

Copy link
Author

@Manankin Manankin Jan 19, 2024

Choose a reason for hiding this comment

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

We use this key to rerender component with clear field
I use touched status to controll if field was used then clear and trying to switch to another field (I show error in this case)

Copy link

@DanilWeda DanilWeda left a comment

Choose a reason for hiding this comment

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

Good job!
I added some comments that touch the clean code side.
Many thanks!

src/App.tsx Outdated
import './App.scss';
import { MoviesList } from './components/MoviesList';
import { NewMovie } from './components/NewMovie';
import moviesFromServer from './api/movies.json';

export const App = () => {
const [preparedMovies, setPreparedMovies] = useState(moviesFromServer);
// const addNewMovie

Choose a reason for hiding this comment

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

remove this comment line

src/App.tsx Outdated
Comment on lines 17 to 19
<NewMovie onAdd={(movie) => {
setPreparedMovies(currentList => [...currentList, movie]);
}}
Copy link

@DanilWeda DanilWeda Jan 22, 2024

Choose a reason for hiding this comment

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

you can write a handler for it ( not critical )

Comment on lines 10 to 11
// Increase the count after successful form submission
// to reset touched status of all the `Field`s
Copy link

@DanilWeda DanilWeda Jan 22, 2024

Choose a reason for hiding this comment

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

Think you can remove it ( not critical )

Comment on lines +35 to +39
setTitle('');
setDescription('');
setImgUrl('');
setImdbUrl('');
setImdbId('');

Choose a reason for hiding this comment

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

You can write function reset for it

<form
className="NewMovie"
key={count}
onSubmit={addNewMovie} // (event) => {}, f(event)

Choose a reason for hiding this comment

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

remove comment line

@Manankin Manankin requested a review from DanilWeda January 22, 2024 12:37
Copy link

@DanilWeda DanilWeda left a comment

Choose a reason for hiding this comment

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

Great job!
Approved.
Many thanks!

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