11import React , { Component } from 'react' ;
22import { NavLink } from 'react-router-dom' ;
3+ import _ from 'lodash' ;
34import { withRouter } from 'react-router-dom' ;
45
56import NavigationItem from '../components/NavigationItem'
@@ -9,10 +10,14 @@ import BellLogo from '../static/images/bell-logo.svg';
910import DropdownArrow from '../static/images/drop-down-arrow.svg' ;
1011import DropdownContent from "../components/DropdownContent" ;
1112
12-
1313class Navbar extends Component {
14- state = {
15- scrolling : false
14+ constructor ( props ) {
15+ super ( props )
16+ this . state = {
17+ scrolling : false ,
18+ }
19+ // use to debounce api call
20+ this . onSearchHandler = _ . debounce ( this . onSearchHandler , 1000 )
1621 }
1722
1823 componentDidMount ( ) {
@@ -33,22 +38,16 @@ class Navbar extends Component {
3338 }
3439 }
3540
36- /** Get the user input */
41+ /** makes api call */
3742 onSearchHandler = ( event ) => {
38- /** Display the movie list. */
39- // navigate to search comp
40- // this.props.history.push('/search)
4143 this . props . history . push ( '/search' )
42- // this.setState({
43- // toggleMovieList: false
44- // });
44+ console . log ( 'helo--' , event . target . value )
45+ }
4546
47+ onChange = ( event ) => {
4648 const userInput = event . target . value ;
47- console . log ( 'user input' , userInput )
48- /** Pass in the user input to make the API call. */
49- // this.makeAipCall(userInput);
50-
51- /** If the input is empty don't display the movie list. */
49+ this . props . history . push ( '/search' )
50+ this . onSearchHandler ( event )
5251 if ( userInput === "" ) {
5352 this . props . history . push ( '/' )
5453 }
@@ -87,43 +86,43 @@ class Navbar extends Component {
8786 } ) . catch ( error => {
8887 console . log ( error ) ;
8988 } ) ;
89+ }
9090
91-
92- render ( ) {
93- const { scrolling, showMovies } = this . state ;
94-
95- return (
96- < nav className = { "navigation " + ( scrolling ? "black" : "" ) } >
97- < ul className = "navigation__container" >
98- < NavLink to = "/" >
99- < img className = "navigation__container--logo" src = { NetflixLogo } alt = "" />
100- </ NavLink >
101- < DropdownArrow className = "navigation__container--downArrow-2" > </ DropdownArrow >
102- < div className = "navigation__container-link pseudo-link" > Home</ div >
103- < div className = "navigation__container-link pseudo-link" > TV Shows</ div >
104- < div className = "navigation__container-link pseudo-link" > Movies</ div >
105- < div className = "navigation__container-link pseudo-link" > Recently Added</ div >
106- < div className = "navigation__container-link pseudo-link" > My List</ div >
107-
108- < div className = "navigation__container--left" >
109- < SearchLogo className = "logo" />
110- < input
111- onChange = { ( ) => this . onSearchHandler ( event ) }
112- className = "navigation__container--left__input"
113- type = "text"
114- placeholder = "Title, genres, people" />
115- </ div >
116-
117- < div className = "navigation__container-link pseudo-link" > KIDS</ div >
118- < div className = "navigation__container-link pseudo-link" > DVD</ div >
119- < BellLogo className = "navigation__container--bellLogo" />
120-
121- < DropdownContent />
122- < DropdownArrow className = "navigation__container--downArrow" />
123- </ ul >
124- </ nav >
125- )
126- }
91+ render ( ) {
92+ const { scrolling, showMovies } = this . state ;
93+
94+ return (
95+ < nav className = { "navigation " + ( scrolling ? "black" : "" ) } >
96+ < ul className = "navigation__container" >
97+ < NavLink to = "/" >
98+ < img className = "navigation__container--logo" src = { NetflixLogo } alt = "" />
99+ </ NavLink >
100+ < DropdownArrow className = "navigation__container--downArrow-2" > </ DropdownArrow >
101+ < div className = "navigation__container-link pseudo-link" > Home</ div >
102+ < div className = "navigation__container-link pseudo-link" > TV Shows</ div >
103+ < div className = "navigation__container-link pseudo-link" > Movies</ div >
104+ < div className = "navigation__container-link pseudo-link" > Recently Added</ div >
105+ < div className = "navigation__container-link pseudo-link" > My List</ div >
106+
107+ < div className = "navigation__container--left" >
108+ < SearchLogo className = "logo" />
109+ < input
110+ onChange = { ( ) => this . onChange ( event ) }
111+ className = "navigation__container--left__input"
112+ type = "text"
113+ placeholder = "Title, genres, people" />
114+ </ div >
115+
116+ < div className = "navigation__container-link pseudo-link" > KIDS</ div >
117+ < div className = "navigation__container-link pseudo-link" > DVD</ div >
118+ < BellLogo className = "navigation__container--bellLogo" />
119+
120+ < DropdownContent />
121+ < DropdownArrow className = "navigation__container--downArrow" />
122+ </ ul >
123+ </ nav >
124+ )
127125 }
126+ }
128127
129- export default withRouter ( Navbar ) ;
128+ export default withRouter ( Navbar ) ;
0 commit comments