-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanner.js
54 lines (49 loc) · 1.48 KB
/
banner.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
import React, { useEffect, useState } from "react";
import axios from "./axios";
import requests from "./requests";
import "./banner.css";
function Banner() {
const [movie, setMovie] = useState([]);
useEffect(() => {
async function fetchData() {
const request = await axios.get(requests.fetchNetflixOriginals);
// console.table(request.data.results)
setMovie(
request.data.results[
Math.floor(Math.random() * request.data.results.length - 1)
]
);
}
fetchData();
}, []);
// console.log(movie);
function truncate(str) {
return String(str).length > 150 ? str.substr(0, 149) + "..." : str;
}
return (
<header
className="banner"
style={{
backgroundSize: "cover",
backgroundImage: `url(
"https://image.tmdb.org/t/p/original${movie.backdrop_path}"
)`,
backgroundPosition: "center center",
}}
>
<div className="bannerContents">
<h1 className="bannerTitle">
{movie.name || movie.title || movie.original_name}
</h1>
<div className="bannerButtons">
<button className="bannerButton">Play</button>
<button className="bannerButton">My List</button>
</div>
<h1 className="bannerDescription">{truncate(movie.overview)}</h1>
</div>
<div className="banner--FadeBottom" />
{/* whenever you are having a modifier, use it like */}
</header>
);
}
export default Banner;