-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathApp.js
More file actions
77 lines (65 loc) · 1.68 KB
/
Copy pathApp.js
File metadata and controls
77 lines (65 loc) · 1.68 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react';
import Search from './Search.js'
import Movies from './Movies.js'
class App extends React.Component {
constructor(){
super();
this.state ={
pageNumber: 1,
searchQuery: "",
movies: [],
videoClass: "video"
}
this.apiCall = this.apiCall.bind(this);
this.submittedSearchQuery = this.submittedSearchQuery.bind(this);
this.receivePaginationQuery = this.receivePaginationQuery.bind(this);
this.receiveVideoBlock = this.receiveVideoBlock.bind(this);
}
componentDidMount(){
}
apiCall(){
var url = `http://www.omdbapi.com/?apikey=77164d83&s=${this.state.searchQuery}&page=${[this.state.pageNumber]}`
fetch(url)
.then(function(response) {
return response.json();
})
.then(body => {
console.log(body.Search)
this.setState({
movies: body.Search
})
})
}
submittedSearchQuery(search){
console.log(search)
this.setState({
pageNumber: 1,
searchQuery: search
},() => this.apiCall()
)
}
receivePaginationQuery(){
this.setState({
pageNumber: ++this.state.pageNumber
},() => this.apiCall()
)
}
receiveVideoBlock(){
this.setState({
videoClass: "video2"
})
}
render(){
return (
<div>
<header><h1>Screen Search</h1></header>
<Search submittedSearchQuery={this.submittedSearchQuery} receivePaginationQuery={this.receivePaginationQuery} receiveVideoBlock={this.receiveVideoBlock}/>
<Movies movies={this.state.movies} />
<div className="main">
<video className={this.state.videoClass} src="007.mp4" autoPlay loop muted></video>
</div>
</div>
)
}
}
export default App;