File size: 2,565 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
81
import React, { useState, useEffect } from "react";
import "./styles.scss";
import PlayCircleFilledWhiteOutlinedIcon from "@material-ui/icons/PlayCircleFilledWhiteOutlined";
import AddOutlinedIcon from "@material-ui/icons/AddOutlined";
import ChatBubbleIcon from "@material-ui/icons/ChatBubble";
import axios from "../../axios";
import { Link } from "react-router-dom";

const HoverScreen = ({ item, api_key, media_type }) => {
  let hours = 0,
    minutes = 0;
  const [media, setMedia] = useState({});

  useEffect(() => {
    async function getData() {
      const response = await axios.get(
        `/${media_type}/${item.id}?api_key=${api_key}`
      );
      setMedia(response.data);
      return response;
    }
    getData();
  }, [item, api_key, media_type]);

  const base_url = "https://image.tmdb.org/t/p/original/";
  if (media.runtime && media.runtime > 0) {
    hours = Math.floor(media.runtime / 60);
    minutes = media.runtime % 60;
  }
  return (
    <div className="hoverScreen">
      <Link
        to={`/${media_type}?id=${item.id}`}
        style={{ textDecoration: "none", color: "white" }}
      >
        <img
          src={`${base_url}${item.backdrop_path}`}
          alt={item.name}
          className="mediaHoverImg"
        />
        <div className="hoverData">
          <div className="hoverHeading">
            <div className="playDiv">
              <div className="playIcon">
                <PlayCircleFilledWhiteOutlinedIcon className="playButton" />
              </div>
              <div className="playtext">Play</div>
            </div>
            <div>
              <AddOutlinedIcon className="addIcon" />
            </div>
          </div>
          <div className="title">
            {item.title ? item.title : item.original_name}
          </div>
          <div className="overview">
            {item.overview.length > 90
              ? item.overview.substr(0, 89) + "..."
              : item.overview}
          </div>
          <div className="footerScreen">
            <div className="runTime">
              {hours > 0 ? `${hours}h ` : ""}
              {minutes > 0 ? `${minutes}min` : ""}
            </div>
            <div className="releaseYear">
              {item.release_date ? item.release_date.substr(0, 4) : ""}
            </div>
            <div>
              <ChatBubbleIcon className="messageIcon" />
            </div>
            <div className="rated">{item.adult ? "18+" : "ALL"}</div>
          </div>
        </div>
      </Link>
    </div>
  );
};

export default HoverScreen;