-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathMovie.js
More file actions
89 lines (83 loc) · 1.98 KB
/
Movie.js
File metadata and controls
89 lines (83 loc) · 1.98 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
import React from "react";
function MovieDetails(props) {
return (
<div className="movie__details">
<h1>Movie details</h1>
<p>
<b>Director: </b>
{props.Director}
</p>
<p>
<b>Actors: </b>
{props.Actors}
</p>
<p>
<b>Awards: </b>
{props.Awards}
</p>
<p>
<b>Runtime: </b>
{props.Runtime}
</p>
<p>
<b>Plot: </b>
{props.Plot}
</p>
</div>
);
}
class Movie extends React.Component {
constructor(props) {
super(props);
this.state = {
showDetails: false,
moreDetails: {},
buttonName: "more details"
};
}
handleClick(movieIdToSearchFor) {
if (this.state.showDetails) {
this.setState({ showDetails: false, buttonName: "more details" });
} else {
fetch(`https://www.omdbapi.com/?i=${movieIdToSearchFor}&apikey=40ce55c`)
.then(response => response.json())
.then(data =>
this.setState({
moreDetails: data,
showDetails: true,
buttonName: "hide details"
})
);
}
}
render() {
return (
<div className="movie">
<div className="movie__top">
<h2>{this.props.title}</h2>
<p>
<b>Release Year: </b> {this.props.year}
</p>
</div>
<div className="movie__middle">
<img className="movie__img" src={this.props.poster} />
</div>
<div className="movie__bottom">
<button
type="button"
className="btn-more"
// onClick={this.handleClick}
// onClick={(event) => this.handleClick(event)}
onClick={() => this.handleClick(this.props.imdbID)}
>
{this.state.buttonName}
</button>
</div>
{this.state.showDetails ? (
<MovieDetails {...this.state.moreDetails} />
) : null}
</div>
);
}
}
export default Movie;