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 solution #2088

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

add task solution #2088

wants to merge 7 commits into from

Conversation

rvoshchylo
Copy link

Copy link

@olya-shyian olya-shyian left a comment

Choose a reason for hiding this comment

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

Nicely done!👍


const sumbitCheck = !(
title.trim() && imageUrl.trim() && imdbUrl.trim() && imdbId.trim()
);
Copy link
Author

Choose a reason for hiding this comment

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

yes, forgot to redeploy

const [description, setDescription] = useState('');
const [imageUrl, setImageUrl] = 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.

instead of creating a lot of states, use just one

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

  const [count, setCount] = useState(0);
  const [newMovie, setNewMovie] = useState(defaultMovie);

src/App.tsx Outdated
</div>
<div className="sidebar">
<NewMovie /* onAdd={(movie) => {}} */ />
<NewMovie onAdd={movie => setMovies([...movies, movie])} />

Choose a reason for hiding this comment

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

move this function into separate handler

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! All good!
Check submit validation. Made it more readable.
Thanks!

Comment on lines +95 to +98
onChange={(newValue => setForm({
...form,
imdbId: newValue,
}))}

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 +84 to +87
onChange={(newValue => setForm({
...form,
imdbUrl: newValue,
}))}

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 +73 to +76
onChange={(newValue => setForm({
...form,
imgUrl: newValue,
}))}

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 +63 to +66
onChange={(newValue => setForm({
...form,
description: newValue,
}))}

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 +52 to +55
onChange={(newValue => setForm({
...form,
title: newValue,
}))}

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 5 to 7
type AddMovie = {
onAdd: (movie: Movie) => void
};

Choose a reason for hiding this comment

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

you can move it in another file ( not critical )

Comment on lines 35 to 38
const sumbitCheck = !(
form.title.trim() && form.imgUrl.trim()
&& form.imdbUrl.trim() && form.imdbId.trim()
);

Choose a reason for hiding this comment

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

try to rewrite for best readability.

Copy link
Author

Choose a reason for hiding this comment

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

?

@rvoshchylo rvoshchylo requested a review from DanilWeda January 17, 2024 11:19
Copy link

@SerhiiKirik SerhiiKirik left a comment

Choose a reason for hiding this comment

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

Great 🔥
Let's make some improvements 🧑‍💻

src/App.tsx Outdated

export const App = () => {
const [movies, setMovies] = useState([...moviesFromServer]);

const handleMovie = (movie: Movie) => setMovies([...movies, movie]);

Choose a reason for hiding this comment

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

use functional setState

Suggested change
const handleMovie = (movie: Movie) => setMovies([...movies, movie]);
const handleMovie = (movie: Movie) => setMovies((...) => ...);


export const NewMovie = () => {
type AddMovie = {

Choose a reason for hiding this comment

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

better to use interface for Props

Suggested change
type AddMovie = {
interface Props = {

Comment on lines 13 to 19
const [form, setForm] = useState({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
} as Movie);

Choose a reason for hiding this comment

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

Suggested change
const [form, setForm] = useState({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
} as Movie);
const [form, setForm] = useState<Movie>({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});


const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
setCount(count + 1);

Choose a reason for hiding this comment

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

functional setState

Comment on lines 24 to 32
setForm({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});

onAdd(form);

Choose a reason for hiding this comment

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

first, you send the form, after - do reset

Suggested change
setForm({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});
onAdd(form);
onAdd(form);
setForm({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});

value=""
onChange={() => {}}
value={form.title}
onChange={(newValue => setForm({

Choose a reason for hiding this comment

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

you can replace this
image
to =>

  onChange={event => onChange(event)}

add name attribute to the input
After that create handleChange function, in this function take this name, title for example, from the event & set with this key ( name )

Copy link
Author

Choose a reason for hiding this comment

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

i dont understand how to do it(

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.
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