-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieInfoComponent.js
115 lines (113 loc) · 3.01 KB
/
MovieInfoComponent.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { useEffect, useState } from "react";
import Axios from "axios";
import { API_KEY } from "../App";
import styled from "styled-components";
const Container = styled.div`
display: flex;
flex-direction: row;
padding: 20px 30px;
justify-content: center;
border-bottom: 1px solid lightgray;
`;
const CoverImage = styled.img`
object-fit: cover;
height: 350px;
`;
const InfoColumn = styled.div`
display: flex;
flex-direction: column;
margin: 20px;
`;
const MovieName = styled.span`
font-size: 22px;
font-weight: 600;
color: black;
margin: 15px 0;
white-space: nowrap;
overflow: hidden;
text-transform: capitalize;
text-overflow: ellipsis;
& span {
opacity: 0.8;
}
`;
const MovieInfo = styled.span`
font-size: 16px;
font-weight: 500;
color: black;
overflow: hidden;
margin: 4px 0;
text-transform: capitalize;
text-overflow: ellipsis;
& span {
opacity: 0.5;
}
`;
const Close = styled.span`
font-size: 16px;
font-weight: 600;
color: black;
background: lightgray;
height: fit-content;
padding: 8px;
border-radius: 50%;
cursor: pointer;
opacity: 0.8;
`;
const MovieInfoComponent = (props) => {
const [movieInfo, setMovieInfo] = useState();
const { selectedMovie } = props;
useEffect(() => {
Axios.get(
`https://www.omdbapi.com/?i=${selectedMovie}&apikey=${API_KEY}`,
).then((response) => setMovieInfo(response.data));
}, [selectedMovie]);
return (
<Container>
{movieInfo ? (
<>
<CoverImage src={movieInfo?.Poster} alt={movieInfo?.Title} />
<InfoColumn>
<MovieName>
{movieInfo?.Type}: <span>{movieInfo?.Title}</span>
</MovieName>
<MovieInfo>
IMDB Rating: <span>{movieInfo?.imdbRating}</span>
</MovieInfo>
<MovieInfo>
Year: <span>{movieInfo?.Year}</span>
</MovieInfo>
<MovieInfo>
Language: <span>{movieInfo?.Language}</span>
</MovieInfo>
<MovieInfo>
Rated: <span>{movieInfo?.Rated}</span>
</MovieInfo>
<MovieInfo>
Released: <span>{movieInfo?.Released}</span>
</MovieInfo>
<MovieInfo>
Runtime: <span>{movieInfo?.Runtime}</span>
</MovieInfo>
<MovieInfo>
Genre: <span>{movieInfo?.Genre}</span>
</MovieInfo>
<MovieInfo>
Director: <span>{movieInfo?.Director}</span>
</MovieInfo>
<MovieInfo>
Actors: <span>{movieInfo?.Actors}</span>
</MovieInfo>
<MovieInfo>
Plot: <span>{movieInfo?.Plot}</span>
</MovieInfo>
</InfoColumn>
<Close onClick={()=>props.onMovieSelect()}>X</Close>
</>
) :
"Loading..."
}
</Container>
);
};
export default MovieInfoComponent;