-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathSearch.js
More file actions
76 lines (65 loc) · 1.6 KB
/
Search.js
File metadata and controls
76 lines (65 loc) · 1.6 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
import React from "react";
const config = {
omd: {
apiKey: "2c6457b6&",
firstSearch: "red",
url: "http://www.omdbapi.com/"
}
};
class Search extends React.Component {
constructor(props) {
super(props);
this.state = {
movie: config.omd.firstSearch
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleClick = this.handleClick.bind(this);
}
fetchMovies() {
fetch(`${config.omd.url}?s=${this.state.movie}&apikey=${config.omd.apiKey}`)
.then(response => response.json())
.then(result => {
this.props.getMovies(result.Search);
})
.catch(error => console.log(error));
}
handleSubmit(event) {
event.preventDefault();
this.fetchMovies();
}
handleChange(event) {
this.setState({
movie: event.target.value
});
}
handleClick(event) {
this.props.hideInfo();
}
componentDidMount() {
this.fetchMovies();
}
render() {
return (
<div className="header">
<h1 className="title">OPEN MOVIE DATABASE SEARCH</h1>
<img
className="moviereel"
src="/Users/phoebedg/workspace/react-cinema/moviereel.png"
alt="Movie Reel"
/>
<form className="form" onSubmit={this.handleSubmit}>
<label />
<input
onClick={this.handleClick}
className="input"
onChange={this.handleChange}
value={this.state.movie}
/>
<button className="button">Go</button>
</form>
</div>
);
}
}
export default Search;