updated modal

This commit is contained in:
andres alcocer
2018-11-14 16:25:13 -05:00
parent df86daef65
commit 369b95d617
5 changed files with 53 additions and 18 deletions

View File

@@ -4,11 +4,10 @@ import React from 'react';
const movieRow = (props) => ( const movieRow = (props) => (
<div className="movie"> <div onClick={props.getMovie} className="movie">
<div className="movie__column-poster"> <div onClick={props.movieDetails} className="movie__column-poster">
<img src={props.movie.posterSrc} alt="" className="movie__poster" /> <img src={props.movie.posterSrc} alt="" className="movie__poster" />
</div> </div>
<button onClick={props.movieDetails}>hellooo</button>
</div> </div>
); );

View File

@@ -1,18 +1,19 @@
import React from 'react'; import React from 'react';
import Aux from '../../../hoc/Aux/Aux'; import Aux from '../../../hoc/Aux/Aux';
import MovieRow from '../MovieRow';
const movieSummary = (props) => ( const movieSummary = (props) => (
// // map object into an array of jsx elemenst // get movieid and make api call
// const movieDetails = Object.keys(props.movies)
// .map(movieKey => { // render data dynamically
// return <p>{movieKey}: {props.movies[movieKey]}</p>
// });
<Aux> <Aux>
{/* <img src="" alt=""/> */} {/* <img src="" alt=""/> */}
<h1>Movie Title</h1> <h1>Movie Title: {props.movieInfo.title}</h1>
<p>rating: 45% realease-date: 2018 runtime: 100m </p> <p>rating: 45% realease-date: 2018 runtime: 100m </p>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nemo, delectus! Veniam error perferendis pariatur atque facere? Repudiandae, quia mollitia sapiente <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nemo, delectus! Veniam error perferendis pariatur atque facere? Repudiandae, quia mollitia sapiente
necessitatibus vitae error assumenda maiores perferendis quaerat excepturi voluptatum quidem?</p> necessitatibus vitae error assumenda maiores perferendis quaerat excepturi voluptatum quidem?</p>

View File

@@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
const backdrop = (props) => ( const backdrop = (props) => (
props.show ? <div props.show ? <div
onClick={props.toggleBackdrop} onClick={props.toggleBackdrop}

View File

@@ -14,7 +14,8 @@ class App extends Component {
toggleMovieList: true, toggleMovieList: true,
//an array that will hold all of our movies component //an array that will hold all of our movies component
rows: [], rows: [],
toggleModal: false toggleModal: false,
movieDetails: {}
} }
makeAipCall = (searchItem) => { makeAipCall = (searchItem) => {
@@ -22,12 +23,11 @@ makeAipCall = (searchItem) => {
axios.get(url) axios.get(url)
.then(res => { .then(res => {
// extract the data from json object // extract the data from json object
console.log(res); // console.log(res);
const movies = res.data.results; const movies = res.data.results;
// console.log(movies); // console.log(movies);
// Holds our movieComponent. // Holds our movieComponent.
let movieRows = []; let movieRows = [];
let total = 0;
movies.forEach((movie) => { movies.forEach((movie) => {
// manually build our image url and set it on the movie object // manually build our image url and set it on the movie object
if (movie.poster_path !== null) { if (movie.poster_path !== null) {
@@ -35,8 +35,8 @@ makeAipCall = (searchItem) => {
// pass in the movie object to our MovieRow component and keep it in a variable called // pass in the movie object to our MovieRow component and keep it in a variable called
// movieComponent // movieComponent
const movieComponent = <MovieRow const movieComponent = <MovieRow
getMovie={this.getMovieDetailsHandler}
movieDetails={this.selectMovieHandler} movieDetails={this.selectMovieHandler}
val={total}
key={movie.id} key={movie.id}
movie={movie}/> movie={movie}/>
// push our movieComponent to our movieRows array; // push our movieComponent to our movieRows array;
@@ -44,6 +44,7 @@ makeAipCall = (searchItem) => {
} }
}) })
// update state // update state
this.setState({ rows: movieRows }); this.setState({ rows: movieRows });
}).catch(error => { }).catch(error => {
@@ -68,13 +69,48 @@ makeAipCall = (searchItem) => {
selectMovieHandler = () => { selectMovieHandler = () => {
this.setState({toggleModal: true}); this.setState({toggleModal: true});
// const url = `https://api.themoviedb.org/3/movie/${movieId}?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&language=en-US`;
// axios.get(url)
// .then(res => {
// console.log(res.data)
// }).catch(error => {
// console.log(error);
// });
} }
closeModal = () => { closeModal = () => {
this.setState({ toggleModal: false }); this.setState({ toggleModal: false });
} }
// get movie details
// return object
getMovieDetailsHandler = (movieId) => {
const url = `https://api.themoviedb.org/3/movie/${503314}?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&language=en-US`;
axios.get(url)
.then(res => {
const movieData = res.data;
console.log(movieData);
this.setState({movieDetails: movieData});
}).catch(error => {
console.log(error);
});
}
render() { render() {
return ( return (
@@ -83,7 +119,7 @@ makeAipCall = (searchItem) => {
{this.state.toggleMovieList ? <Layout /> : <div //onClick={this.onChangeHandler} {this.state.toggleMovieList ? <Layout /> : <div //onClick={this.onChangeHandler}
className="search-container">{this.state.rows}</div>} className="search-container">{this.state.rows}</div>}
<Modal show={this.state.toggleModal} modalClosed={this.closeModal}> <Modal show={this.state.toggleModal} modalClosed={this.closeModal}>
<MovieSummary /> <MovieSummary movieInfo={this.state.movieDetails}/>
</Modal> </Modal>
</div> </div>

View File

@@ -5,5 +5,5 @@
z-index: 100; z-index: 100;
left: 0; left: 0;
top: 0; top: 0;
background-color: rgba($color-background, .5); background-color: rgba($color-background, .7);
} }