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