-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBanner.js
More file actions
57 lines (46 loc) · 1.57 KB
/
Banner.js
File metadata and controls
57 lines (46 loc) · 1.57 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
import React, { useEffect, useState } from 'react'
import './Banner.css'
import axios from './axios';
import requests from './Requests';
function Banner() {
const[movie, setMovie] = useState([]);
useEffect(() => {
async function fetchData(){
const request = await axios.get(requests.fetchNetflixOriginals);
setMovie(
request.data.results[
Math.floor(Math.random() * request.data.results.length -1)
]
);
return request;
}
fetchData();
}, []);
console.log(movie);
function truncate(string, n){
return string?.length > n ? string.substr(0,n-1) + '...' : string;
}
return(
<header
className="banner"
style={{
backgroundSize: "cover",
backgroundImage: `url("https://image.tmdb.org/t/p/original/${movie?.backdrop_path}")`,
backgroundPosition: "center center"
}}
>
<div className='banner__contents'>
<h1 className='banner__title'>{movie?.title || movie?.name || movie?.originalname}</h1>
<div className='banner__buttons'>
<button className='banner__button'>Play</button>
<button className='banner__button'>My List</button>
</div>
<h1 className='banner__description'>
{truncate(movie?.overview, 150)}
</h1>
</div>
<div className='banner--fadeBottom' />
</header>
);
}
export default Banner