-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (39 loc) · 1.22 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
50
51
52
53
54
55
56
57
58
59
60
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';
//Create a new component, this component should produce some html
// Take this component's generated HTML and put it on the page (in the DOM)
const API_KEY = 'AIzaSyCQPz1p70xRCSushwbKdIh_sxOGDU5pBuw';
class App extends Component {
constructor(props) {
super(props);
this.state = {
videos : [],
selectedVideo : null
};
this.videoSearch('surfboards');
}
videoSearch(term) {
YTSearch({key : API_KEY, term : term}, (videos) => {
this.setState({ videos: videos,
selectedVideo: videos[0]
});
});
}
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>
);
}
}
ReactDOM.render(<App/>, document.querySelector('.container'));