From 7d513456999a712c0f295c957896e2d8006d09c6 Mon Sep 17 00:00:00 2001 From: Mike Pinchuk <61156291+mike-pinchuk@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:25:09 +0300 Subject: [PATCH] fixed some issues --- src/components/MovieItem.jsx | 122 ++++++++++++++++------------------- 1 file changed, 56 insertions(+), 66 deletions(-) diff --git a/src/components/MovieItem.jsx b/src/components/MovieItem.jsx index 1d2804e..0f102e9 100644 --- a/src/components/MovieItem.jsx +++ b/src/components/MovieItem.jsx @@ -1,70 +1,60 @@ -import React from "react"; +import React from 'react' -class MovieItem extends React.Component { - state = { - willWatch: false - }; - render() { - const { - data, - deleteMovie, - addMovieToWillWatch, - deleteMovieFromWillWatch - } = this.props; - // props.data = {}; - return ( -
- -
-
{data.title}
-
-

Rating: {data.vote_average}

- {this.state.willWatch ? ( - - ) : ( - - )} -
- -
-
- ); - } +class MovieItem extends React.PureComponent { + constructor() { + super() + + this.state = { + willWatch: false + } + + } + + addWillWatch = movie => { + this.setState({ + willWatch: true + }); + this.props.addMovieToWillWatchList(movie) + } + + removeWillWatch = movie => { + this.setState({ + willWatch: false + }); + this.props.removeMovieFromWillWatch(movie) + } + + render() { + const { movie, removeMovie, addMovieToWillWatchList, removeMovieFromWillWatch } = this.props + return ( +
+ +
+
{movie.title}
+
+

Rating: {movie.vote_average}

+ {this.state.willWatch ? + : + } + +
+ +
+
+ ) + } } -export default MovieItem; + + +export default MovieItem