File size: 3,358 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from "react";
import "./ItemPageFooter.scss";
import { connect } from "react-redux";
import {
  selectMovieCast,
  selectMovieVideos
} from "../../Redux/Movie/movie-selectors";
import { selectTVCast, selectTVVideos } from "../../Redux/TVShow/tv-selectors";
import { faPlay, faPlus, faCheck } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import ItemPageCast from "../ItemPageCast/ItemPageCast";
import { TRAILER_LINK } from "../../Config/config";
import { addItem, removeItem } from "../../Redux/List/list-actions";
import { selectListItems } from "../../Redux/List/list-selectors";

const ItemPageFooter = ({

  item,

  movieCast,

  movieVideos,

  addItem,

  removeItem,

  tvCast,

  tvVideos,

  movies,

  tvshow,

  listItems

}) => {
  const existingItem = listItems.filter(listItem => listItem.id === item.id);
  return (
    <div className="item-page-footer">

      <div className="item-page-footer__container">

        {movies && movieCast.length

          ? movieCast

              .filter((item, index) => index < 4)

              .map(({ id, profile_path, ...otherProps }) =>

                profile_path ? (

                  <ItemPageCast

                    key={id}

                    profile_path={profile_path}

                    {...otherProps}

                  />

                ) : null

              )

          : null}

        {tvshow && tvCast.length

          ? tvCast

              .filter((item, index) => index < 4)

              .map(({ id, profile_path, ...otherProps }) =>

                profile_path ? (

                  <ItemPageCast

                    key={id}

                    profile_path={profile_path}

                    {...otherProps}

                  />

                ) : null

              )

          : null}

      </div>



      <div className="item-page-footer__btn-container">

        {existingItem.length ? (

          <button className="item-page-footer__btn" onClick={() => removeItem(item)}>

            <FontAwesomeIcon icon={faCheck} className="item-page-footer__icon" />

            Added To List

          </button>

        ) : (

          <button className="item-page-footer__btn" onClick={() => addItem(item)}>

            <FontAwesomeIcon icon={faPlus} className="item-page-footer__icon" />

            My List

          </button>

        )}



        <button

          onClick={() => {

            return movies

              ? window.open(`${TRAILER_LINK}${movieVideos}`, "_blank")

              : window.open(`${TRAILER_LINK}${tvVideos}`, "_blank");

          }}

          className="item-page-footer__btn"

        >

          <FontAwesomeIcon icon={faPlay} className="item-page-footer__icon" />

          Watch Trailer

        </button>

      </div>

    </div>
  );
};

const mapDispatchToProps = dispatch => ({
  addItem: item => dispatch(addItem(item)),
  removeItem: item => dispatch(removeItem(item))
});

const mapStateToProps = state => ({
  movieCast: selectMovieCast(state),
  movieVideos: selectMovieVideos(state),
  tvCast: selectTVCast(state),
  tvVideos: selectTVVideos(state),
  listItems: selectListItems(state)
});

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ItemPageFooter);