-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathApp.js
More file actions
102 lines (91 loc) · 2.36 KB
/
App.js
File metadata and controls
102 lines (91 loc) · 2.36 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React from "react";
import Search from "./Search";
import Results from "./Results";
import MoreInfo from "./MoreInfo";
const config = {
apiKey: "77c3b516",
url: "http://www.omdbapi.com/?i="
};
class App extends React.Component {
constructor(props) {
super();
this.state = {
films: [],
showDetailedInfo: false,
imdbLink: "https://www.imdb.com/title/",
imdbID: "",
details: {},
errorPic: "./assets/woops.jpg"
};
this.recieveFilmInfo = this.recieveFilmInfo.bind(this);
this.recieveMoreInfo = this.recieveMoreInfo.bind(this);
this.closeDetails = this.closeDetails.bind(this);
}
recieveFilmInfo(results) {
this.setState({
films: results.Search,
imdbID: results.Search.imdbID
});
}
recieveMoreInfo(imdbID) {
this.setState({
imdbID,
showDetailedInfo: true
});
this.fetchDetails(imdbID);
}
closeDetails(showDetailedInfo) {
this.setState({
showDetailedInfo: false
});
}
fetchDetails(imdbID) {
fetch(`${config.url}${imdbID}&plot=small&apikey=${config.apiKey}`)
.then(response => response.json())
.then(data => {
this.setState({
details: data
});
});
}
render() {
return (
<div>
<header>
<h1 className="header">Hamzah's Online Movie Search Engine</h1>
</header>
<Search recieveFilmInfo={this.recieveFilmInfo} />
<div className="results_container" id="show_results">
<Results
recieveMoreInfo={this.recieveMoreInfo}
recieveFavourite={this.recieveFavourite}
fetchDetails={this.fetchDetails}
imdbLink={this.state.imdbLink}
films={this.state.films}
imdbID={this.state.imdbID}
errorPic={this.errorPic}
favourites={this.state.favourites}
/>
</div>
{this.state.showDetailedInfo ? (
<MoreInfo
closeDetails={this.closeDetails}
details={this.state.details}
/>
) : null}
<div className="footer">
<footer>
<a
className="a__links"
href="http://www.omdbapi.com/"
target="_blank"
>
Powered by OMDB
</a>
</footer>
</div>
</div>
);
}
}
export default App;