-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMovieInfo.jsx
More file actions
169 lines (143 loc) · 3.25 KB
/
Copy pathMovieInfo.jsx
File metadata and controls
169 lines (143 loc) · 3.25 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { useParams } from "react-router-dom";
import { useEffect, useState } from "react";
import styled from "styled-components";
import NavLink from "../Components/NavLink";
//styling
const TopNav = styled.div`
display: flex;
position: absolute;
top: 20px;
z-index: 10;
`;
const InfoRow = styled.div`
display: flex;
flex-direction: column;
align-items: left;
gap: 15px;
padding: 20px;
z-index: 1;
box-sizing: border-box;
@media (min-width: 768px) {
flex-direction: row;
align-items: flex-end;
gap: 30px;
padding: 50px;
}
`;
const InfoText = styled.div`
display: flex;
flex-direction: column;
max-width: 100%;
gap: 10px;
@media (min-width: 768px) {
max-width: 400px;
}
`;
const Backdrop = styled.div`
width: 100%;
min-height: 100vh;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
position: relative;
display: flex;
align-items: column;
&::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(rgba(0,0,0,0)0%, rgba(0,0,0,0.9) 90%);
}
@media (min-width: 768px) {
height: 100vh;
align-items: flex-end;
}
`;
const Poster = styled.div`
width: 100%;
height: 80%;
max-width: 60%;
aspect-ratio: 2 / 3;
border: 6px solid white;
margin-top: 60px;
img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
`;
const TitleRow = styled.div`
align-items: center;
gap: 2px;
@media (min-width: 768px) {
display: flex;
}
`;
const Title = styled.h1`
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
@media (min-width: 768px) {
margin-top: 330px;
}
`;
const Rating = styled.span`
background-color: #ffffffad;
color: black;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
font-weight: bold;
border-radius: 2px;
padding: 0.2rem 0.5rem;
font-size: 1rem;
margin-top: 0px;
@media (min-width: 768px) {
margin-top: 330px;
}
`;
const Info = styled.p`
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
font-size: 12px;
`;
//component
export const MovieInfo = () => {
const { id } = useParams();
const [movie, setMovie] = useState(null);
//fetching API
useEffect(() => {
fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=a2b94bfec7b2f944f7fff21bcd94ef06&language=en-US`)
.then(res => res.json())
.then(data => setMovie(data))
.catch(err => console.error(err));
}, [id]);
if (!movie) return <p>Loading...</p>;
const posterUrl = `https://image.tmdb.org/t/p/w342${movie.poster_path}`;
//backdrop, movie poster and info
return (
<>
<Backdrop
style={{
backgroundImage: `url(https://image.tmdb.org/t/p/w1280${movie.backdrop_path})`
}}
>
<TopNav>
<NavLink to="/"> ⬅ Movies</NavLink>
</TopNav>
<InfoRow>
<Poster>
<img src={posterUrl} alt={movie.title} />
</Poster>
<InfoText>
<TitleRow>
<Title>{movie.title}</Title>
<Rating> ⭐️ {movie.vote_average.toFixed(1)}</Rating>
</TitleRow>
<Info>{movie.overview}</Info>
</InfoText>
</InfoRow >
</Backdrop>
</>
);
}