search items functionality
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
import React from 'react';
|
import React, {Component} from 'react';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const movieRow = (props) => (
|
const movieRow = (props) => (
|
||||||
|
|
||||||
<div onClick={props.getMovie} className="movie">
|
<div className="movie">
|
||||||
<div onClick={props.movieDetails} className="movie__column-poster">
|
<div onClick={props.movieDetails} className="movie__column-poster">
|
||||||
<img src={props.movie.posterSrc} alt="" className="movie__poster" />
|
<img src={props.movieImage} alt="" className="movie__poster" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,18 +5,13 @@ import MovieRow from '../MovieRow';
|
|||||||
|
|
||||||
const movieSummary = (props) => (
|
const movieSummary = (props) => (
|
||||||
|
|
||||||
// get movieid and make api call
|
|
||||||
|
|
||||||
// render data dynamically
|
|
||||||
|
|
||||||
|
|
||||||
<Aux>
|
<Aux>
|
||||||
|
<h1 className="modal__title">{props.movie.title}</h1>
|
||||||
{/* <img src="" alt=""/> */}
|
<p className="modal__info">
|
||||||
<h1>Movie Title: {props.movieInfo.title}</h1>
|
<span className="modal__rating">Rating: {props.movie.vote_average * 10}% </span>
|
||||||
<p>rating: 45% realease-date: 2018 runtime: 100m </p>
|
Release date: {props.movie.release_date} Runtime: {props.movie.runtime}m
|
||||||
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nemo, delectus! Veniam error perferendis pariatur atque facere? Repudiandae, quia mollitia sapiente
|
</p>
|
||||||
necessitatibus vitae error assumenda maiores perferendis quaerat excepturi voluptatum quidem?</p>
|
<p className="modal__overview">{props.movie.overview}</p>
|
||||||
<button>Play</button>
|
<button>Play</button>
|
||||||
<button>My list</button>
|
<button>My list</button>
|
||||||
<p>staring: mdf gglo bool emmy djf </p>
|
<p>staring: mdf gglo bool emmy djf </p>
|
||||||
|
|||||||
@@ -15,36 +15,34 @@ class App extends Component {
|
|||||||
//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: {}
|
movieDetails: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
makeAipCall = (searchItem) => {
|
makeAipCall = (searchItem) => {
|
||||||
const url = "https://api.themoviedb.org/3/search/movie?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&page=1&query=" + searchItem;
|
const url = `https://api.themoviedb.org/3/search/multi?api_key=9ea839ec7891591994ec0f540b4b199f&language=en-US&include_adult=false&query=${searchItem}`;
|
||||||
axios.get(url)
|
axios.get(url)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
console.log(res.data.results);
|
||||||
// extract the data from json object
|
// extract the data from json object
|
||||||
// console.log(res);
|
const results = res.data.results;
|
||||||
const movies = res.data.results;
|
let movieImageUrl;
|
||||||
// console.log(movies);
|
|
||||||
// Holds our movieComponent.
|
|
||||||
let movieRows = [];
|
let movieRows = [];
|
||||||
movies.forEach((movie) => {
|
results.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 && movie.media_type !== "person") {
|
||||||
movie.posterSrc = "https://image.tmdb.org/t/p/w185" + movie.poster_path;
|
movieImageUrl = "https://image.tmdb.org/t/p/w500" + movie.poster_path;
|
||||||
// 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(movie.id)}
|
||||||
movieDetails={this.selectMovieHandler}
|
|
||||||
key={movie.id}
|
key={movie.id}
|
||||||
movie={movie}/>
|
movieImage={movieImageUrl}
|
||||||
|
movie={movie} />
|
||||||
// push our movieComponent to our movieRows array;
|
// push our movieComponent to our movieRows array;
|
||||||
movieRows.push(movieComponent);
|
movieRows.push(movieComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
this.setState({ rows: movieRows });
|
this.setState({ rows: movieRows });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
@@ -67,28 +65,10 @@ makeAipCall = (searchItem) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectMovieHandler = () => {
|
selectMovieHandler = (movieId) => {
|
||||||
this.setState({toggleModal: true});
|
this.setState({toggleModal: true});
|
||||||
|
console.log(movieId);
|
||||||
|
const url = `https://api.themoviedb.org/3/movie/${movieId}?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&append_to_response=tv,videos`;
|
||||||
// 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 = () => {
|
|
||||||
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)
|
axios.get(url)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
|
||||||
@@ -99,17 +79,12 @@ makeAipCall = (searchItem) => {
|
|||||||
|
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeModal = () => {
|
||||||
|
this.setState({ toggleModal: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
@@ -119,10 +94,10 @@ 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 movieInfo={this.state.movieDetails}/>
|
<MovieSummary movie={this.state.movieDetails}/>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,14 +106,11 @@ export default App;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get primary information about movie
|
|
||||||
//const url =
|
|
||||||
// "https://api.themoviedb.org/3/search/movie?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&page=1&query=" +
|
|
||||||
// searchItem;
|
|
||||||
|
|
||||||
// curl --request GET \
|
// curl --request GET \
|
||||||
// --url 'https://api.themoviedb.org/3/movie/503314?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&language=en-US' \
|
// --url 'https://api.themoviedb.org/3/find/ur95210597?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&language=en-US&external_source=imdb_id' \
|
||||||
// --data '{}'
|
// --data '{}'
|
||||||
|
|
||||||
// https://api.themoviedb.org/3/movie/{movie_id}?api_key=<<api_key>>&language=en-US
|
|
||||||
|
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
$color-dark: #171818;
|
$color-dark: #171818;
|
||||||
$color-background: #141414;
|
$color-background: #141414;
|
||||||
|
$color-background-modal: #000000;
|
||||||
$color-white: rgb(221, 218, 218);
|
$color-white: rgb(221, 218, 218);
|
||||||
|
|
||||||
$color-green: #1cb831;
|
$color-green: #1cb831;
|
||||||
|
$color-green-modal: rgb(92, 223, 92);
|
||||||
|
$color-modal-grey: rgb(172, 171, 171);
|
||||||
|
|
||||||
$color-red: #e21221;
|
$color-red: #e21221;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,36 @@
|
|||||||
.modal {
|
.modal {
|
||||||
|
padding-left: 4rem;
|
||||||
|
padding-top: 2rem;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 500;
|
z-index: 500;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
top: 30%;
|
top: 30%;
|
||||||
left: 0;
|
left: 0;
|
||||||
height: 42rem;
|
color: white;
|
||||||
background: yellowgreen;
|
height: 44rem;
|
||||||
|
background: $color-background-modal;
|
||||||
transition: all 1s;
|
transition: all 1s;
|
||||||
transform: scale(0);
|
transform: scale(0);
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-size: 4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__rating {
|
||||||
|
font-size: 2rem;
|
||||||
|
color: $color-green-modal;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__info {
|
||||||
|
padding-top: 1.6rem;
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__overview {
|
||||||
|
color: $color-modal-grey;
|
||||||
|
padding-top: 2rem;
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.show {
|
.show {
|
||||||
|
|||||||
Reference in New Issue
Block a user