diff --git a/src/containers/AppRouter.js b/src/containers/AppRouter.js index 2221cbe..0c37b94 100644 --- a/src/containers/AppRouter.js +++ b/src/containers/AppRouter.js @@ -1,16 +1,21 @@ import React from 'react'; import { BrowserRouter, Route, Switch } from 'react-router-dom'; -import Layout from './Layout'; +import Home from './Home'; import NotFound from './NotFound'; +import Search from './Search'; +import Navbar from './Navbar'; const AppRouter = () => ( - - - - - + <> + + + + + + + ); diff --git a/src/containers/Layout.js b/src/containers/Home.js similarity index 88% rename from src/containers/Layout.js rename to src/containers/Home.js index c1ef949..1914ced 100644 --- a/src/containers/Layout.js +++ b/src/containers/Home.js @@ -7,13 +7,12 @@ import Movie from '../components/Movie/Movie'; import Modal from '../components/UI/Modal'; import MovieDetails from '../components/Movie/MovieDetails'; -class Layout extends Component { - +class Home extends Component { state = { /** Toggles the movie list when the user starts typing. */ toggleMovieList: true, /** An array that will hold all of our movie Components. */ - MovieList: [], + // MovieList: [], /** Toggles the modal when a movie is clicked. */ toggleModal: false, /** Holds the movie information for a single movie. */ @@ -58,9 +57,12 @@ class Layout extends Component { /** Get the user input */ onSearchHandler = (event) => { /** Display the movie list. */ - this.setState({ - toggleMovieList: false - }); + // navigate to search comp + // this.props.history.push('/search) + this.props.history.push('/search') + // this.setState({ + // toggleMovieList: false + // }); const userInput = event.target.value; /** Pass in the user input to make the API call. */ @@ -106,8 +108,11 @@ class Layout extends Component { render() { return (
- - + {/* */} + { + this.state.toggleMovieList ? :
{this.state.MovieList}
+ } @@ -118,4 +123,4 @@ class Layout extends Component { } } -export default Layout; \ No newline at end of file +export default Home; \ No newline at end of file diff --git a/src/containers/Navbar.js b/src/containers/Navbar.js index bdf99d8..6d20a35 100644 --- a/src/containers/Navbar.js +++ b/src/containers/Navbar.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import { NavLink } from 'react-router-dom'; +import { withRouter } from 'react-router-dom'; import NavigationItem from '../components/NavigationItem' import SearchLogo from '../static/images/search-icon.svg'; @@ -9,7 +10,7 @@ import DropdownArrow from '../static/images/drop-down-arrow.svg'; import DropdownContent from "../components/DropdownContent"; -class navigation extends Component { +class Navbar extends Component { state = { scrolling: false } @@ -32,42 +33,97 @@ class navigation extends Component { } } - render() { - const { scrolling } = this.state; - const { showMovies } = this.props; + /** Get the user input */ + onSearchHandler = (event) => { + /** Display the movie list. */ + // navigate to search comp + // this.props.history.push('/search) + this.props.history.push('/search') + // this.setState({ + // toggleMovieList: false + // }); - return ( - - ) + /** If the input is empty don't display the movie list. */ + if (userInput === "") { + this.props.history.push('/') + } } -} -export default navigation; + /** Make API call as soon as the user starts typing. */ + makeAipCall = (searchItem) => { + const url = `/search/multi?api_key=${process.env.API_KEY}&language=en-US&include_adult=false&query=${searchItem}`; + + axios.get(url) + .then(res => { + const results = res.data.results; + let movieImageUrl; + /** Will hold all our movies Components */ + let movieRows = []; + + /** Loop through all the movies */ + results.forEach((movie) => { + /** Manually build our image url and set it on the Movie component. */ + if (movie.poster_path !== null && movie.media_type !== "person") { + movieImageUrl = "https://image.tmdb.org/t/p/w500" + movie.poster_path; + + /** Set the movie object to our Movie component */ + const movieComponent = this.selectMovieHandler(movie)} + key={movie.id} + movieImage={movieImageUrl} + movie={movie} /> + + /** Push our movie component to our movieRows array */ + movieRows.push(movieComponent); + } + }) + /** Set our MovieList array to the movieRows array */ + this.setState({ MovieList: movieRows }); + }).catch(error => { + console.log(error); + }); + + + render() { + const { scrolling, showMovies } = this.state; + + return ( + + ) + } + } + + export default withRouter(Navbar); diff --git a/src/containers/Search.js b/src/containers/Search.js new file mode 100644 index 0000000..1bb3a1a --- /dev/null +++ b/src/containers/Search.js @@ -0,0 +1,11 @@ +import React, { Component } from 'react'; + +export default class Search extends Component { + state = { + movieList: []; + } + + render() { + return
{this.state.movieList}
; + } +}