-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
56 lines (49 loc) · 1.33 KB
/
App.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
import React from 'react';
import SearchBar from './SearchBar';
import youtube from '../apis/youtube';
import VideoList from './VideoList';
import VideoDetail from './VideoDetail';
class App extends React.Component {
state = { videos: [], selectedVideo: null, defaultTerm: 'Kuala Bears' };
componentDidMount() {
this.onTermSubmit(this.state.defaultTerm);
}
onTermSubmit = async (term) => {
const response = await youtube.get('/search', {
params: {
q: term
}
});
this.setState({
videos: response.data.items,
selectedVideo: response.data.items[0]
});
};
onVideoSelect = (video) => {
this.setState({ selectedVideo: video });
};
render() {
return (
<div className="ui container">
<SearchBar
onFormSubmit={this.onTermSubmit}
defaultTerm={this.state.defaultTerm}
/>
<div className="ui grid">
<div className="ui row">
<div className="eleven wide column">
<VideoDetail video={this.state.selectedVideo} />
</div>
<div className="five wide column">
<VideoList
videos={this.state.videos}
onVideoSelect={this.onVideoSelect}
/>
</div>
</div>
</div>
</div>
);
}
}
export default App;