summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/DisplayItem/generic/ItemOverview.tsx
blob: 1c06b5d2508df113ba5b6ab7607bbcbfbf0aafdb (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {
  faBookmark as farBookmark,
  faClone as fasClone,
  faFolder,
} from "@fortawesome/free-regular-svg-icons";
import {
  faBookmark,
  faLanguage,
  faMusic,
  faStream,
  faTags,
  IconDefinition,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React, { FunctionComponent, useMemo } from "react";
import {
  Badge,
  Col,
  Container,
  Image,
  OverlayTrigger,
  Popover,
  Row,
} from "react-bootstrap";
import { useProfileBy, useProfileItemsToLanguages } from "../../@redux/hooks";
import { LanguageText } from "../../components";
import { BuildKey, isMovie } from "../../utilities";

interface Props {
  item: Item.Base;
  details?: { icon: IconDefinition; text: string }[];
}

const ItemOverview: FunctionComponent<Props> = (props) => {
  const { item, details } = props;

  const detailBadges = useMemo(() => {
    const badges: (JSX.Element | null)[] = [];
    badges.push(
      <DetailBadge key="file-path" icon={faFolder} desc="File Path">
        {item.path}
      </DetailBadge>
    );

    badges.push(
      ...(details?.map((val, idx) => (
        <DetailBadge key={BuildKey(idx, "detail", val.text)} icon={val.icon}>
          {val.text}
        </DetailBadge>
      )) ?? [])
    );

    if (item.tags.length > 0) {
      badges.push(
        <DetailBadge key="tags" icon={faTags} desc="Tags">
          {item.tags.join("|")}
        </DetailBadge>
      );
    }

    return badges;
  }, [details, item.path, item.tags]);

  const audioBadges = useMemo(
    () =>
      item.audio_language.map((v, idx) => (
        <DetailBadge
          key={BuildKey(idx, "audio", v.code2)}
          icon={faMusic}
          desc="Audio Language"
        >
          {v.name}
        </DetailBadge>
      )),
    [item.audio_language]
  );

  const profile = useProfileBy(item.profileId);
  const profileItems = useProfileItemsToLanguages(profile);

  const languageBadges = useMemo(() => {
    const badges: (JSX.Element | null)[] = [];

    if (profile) {
      badges.push(
        <DetailBadge
          key="language-profile"
          icon={faStream}
          desc="Languages Profile"
        >
          {profile.name}
        </DetailBadge>
      );

      badges.push(
        ...profileItems.map((v, idx) => (
          <DetailBadge
            key={BuildKey(idx, "lang", v.code2)}
            icon={faLanguage}
            desc="Language"
          >
            <LanguageText long text={v}></LanguageText>
          </DetailBadge>
        ))
      );
    }

    return badges;
  }, [profile, profileItems]);

  const alternativePopover = useMemo(
    () => (
      <Popover id="item-overview-alternative">
        <Popover.Title>Alternate Titles</Popover.Title>
        <Popover.Content>
          {item.alternativeTitles.map((v, idx) => (
            <li key={idx}>{v}</li>
          ))}
        </Popover.Content>
      </Popover>
    ),
    [item.alternativeTitles]
  );

  return (
    <Container
      fluid
      style={{
        backgroundRepeat: "no-repeat",
        backgroundSize: "cover",
        backgroundPosition: "top center",
        backgroundImage: `url('${item.fanart}')`,
      }}
    >
      <Row
        className="p-4 pb-4"
        style={{
          backgroundColor: "rgba(0,0,0,0.7)",
        }}
      >
        <Col sm="auto">
          <Image
            className="d-none d-sm-block my-2"
            style={{
              maxHeight: 250,
            }}
            src={item.poster}
          ></Image>
        </Col>
        <Col>
          <Container fluid className="text-white">
            <Row>
              {isMovie(item) ? (
                <FontAwesomeIcon
                  className="mx-2 mt-2"
                  title={item.monitored ? "monitored" : "unmonitored"}
                  icon={item.monitored ? faBookmark : farBookmark}
                  size="2x"
                ></FontAwesomeIcon>
              ) : null}
              <h1>{item.title}</h1>
              <span hidden={item.alternativeTitles.length === 0}>
                <OverlayTrigger overlay={alternativePopover}>
                  <FontAwesomeIcon
                    className="mx-2"
                    icon={fasClone}
                  ></FontAwesomeIcon>
                </OverlayTrigger>
              </span>
            </Row>
            <Row>{detailBadges}</Row>
            <Row>{audioBadges}</Row>
            <Row>{languageBadges}</Row>
            <Row>
              <span>{item.overview}</span>
            </Row>
          </Container>
        </Col>
      </Row>
    </Container>
  );
};

interface ItemBadgeProps {
  icon: IconDefinition;
  children: string | JSX.Element;
  desc?: string;
}

const DetailBadge: FunctionComponent<ItemBadgeProps> = ({
  icon,
  desc,
  children,
}) => (
  <Badge title={desc} variant="secondary" className="mr-2 my-1 text-truncate">
    <FontAwesomeIcon icon={icon}></FontAwesomeIcon>
    <span className="ml-1">{children}</span>
  </Badge>
);

export default ItemOverview;