Skip to content

Commit

Permalink
typing fires a new search
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Dec 21, 2015
1 parent 49d5009 commit a67f76e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/search_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class SearchBar extends Component {
<div className="search-bar">
<input
value={this.state.term}
onChange={event => this.setState({ term: event.target.value })} />
onChange={event => this.onInputChange(event.target.value)} />
</div>
);
}

onInputChange(term) {
this.setState({term});
this.props.onSearchTermChange(term);
}
}

export default SearchBar;
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class App extends Component {
selectedVideo: null
};

YTSearch({key: API_KEY, term: 'surfboards'}, (videos) => {
this.videoSearch('surfboards');
}

videoSearch(term) {
YTSearch({key: API_KEY, term: term}, (videos) => {
this.setState({
videos: videos,
selectedVideo: videos[0]
Expand All @@ -26,7 +30,7 @@ class App extends Component {
render() {
return (
<div>
<SearchBar />
<SearchBar onSearchTermChange={term => this.videoSearch(term)} />
<VideoDetail video={this.state.selectedVideo} />
<VideoList
onVideoSelect={selectedVideo => this.setState({selectedVideo}) }
Expand Down

0 comments on commit a67f76e

Please sign in to comment.