-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (42 loc) · 1.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import _ from 'lodash';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import YTSearch from 'youtube-api-search';
import SearchBar from './components/search_bar';
import VideoList from './components/video_list';
import VideoDetail from './components/video_detail';
const API_KEY = 'AIzaSyDhi6AUOFBNVu4Pog60lucwW7UfFE45OLQ';
//Create a new component. This component should produce some HTML
class App extends Component {
constructor(props) {
super(props);
this.state = {
videos: [],
selectedVideo: null
};
this.videoSearch('paintball');
}
videoSearch(term) {
YTSearch({ key: API_KEY, term: term }, (videos) => {
this.setState({
videos: videos,
selectedVideo: videos[0]
});
//this.setState({ videos: videos });
});
}
render() {
const videoSearch = _.debounce((term) => { this.videoSearch(term) }, 300);
return (
<div>
<SearchBar onSearchTermChange={videoSearch} />
<VideoDetail video={this.state.selectedVideo} />
<VideoList
onVideoSelect={selectedVideo => this.setState({selectedVideo})}
videos={this.state.videos} />
</div>
);
}
}
//Take this component's generatred HTML and put it on the page (in the DOM)
ReactDOM.render(<App />, document.querySelector('.container'));