File size: 2,155 Bytes
f5071ca |
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 |
import React, { useState, useEffect } from "react";
import axios from "../../axios";
import "./styles.scss";
const Slideshow = ({ fetch_url, api_key }) => {
const [sshow, setSshow] = useState([]);
const base_url = "https://image.tmdb.org/t/p/original/";
var startSS = 0;
var temp_int;
const automaticSlideshow = () => {
const x = document.getElementsByClassName("ssDiv");
var i;
if (x.length === 0) {
clearInterval(temp_int);
}
for (i = 0; i < sshow.length && x.length > 0; i++) {
if (i === startSS) {
x[i].style.display = "block";
x[i].style.width = "100%";
} else {
x[i].style.display = "none";
x[i].style.width = "0%";
}
}
startSS++;
if (sshow.length > 0 && startSS === sshow.length) {
startSS = 0;
}
};
temp_int = setInterval(automaticSlideshow, 5000);
useEffect(() => {
async function fetchData() {
const response = await axios.get(fetch_url + `?api_key=${api_key}`);
setSshow(response.data.results);
return response;
}
fetchData();
}, [fetch_url, api_key]);
return (
<div>
{sshow.map((item) => {
return (
<div key={item.id} className="ssDiv">
<div>
<img
src={`${base_url}${item.backdrop_path}`}
alt={item.name}
className="slideshowImg"
/>
<div className="SSdescription">
<div className="ssTitle">
{item.original_title
? item.original_title
: item.original_name}
</div>
<div className="ssOverview">{item.overview}</div>
{/* <div className="ssVote">
Media Type:{" "}
{item.media_type === "tv"
? item.media_type.toUpperCase()
: item.media_type.charAt(0).toUpperCase() +
item.media_type.slice(1)}
</div> */}
</div>
</div>
</div>
);
})}
</div>
);
};
export default Slideshow;
|