Sonarr/frontend/src/AddSeries/AddNewSeries/AddNewSeriesSearchResult.js

228 lines
5.6 KiB
JavaScript
Raw Normal View History

2018-01-13 02:01:27 +00:00
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { icons, kinds, sizes } from 'Helpers/Props';
import HeartRating from 'Components/HeartRating';
import Icon from 'Components/Icon';
import Label from 'Components/Label';
import Link from 'Components/Link/Link';
import SeriesPoster from 'Series/SeriesPoster';
import AddNewSeriesModal from './AddNewSeriesModal';
import styles from './AddNewSeriesSearchResult.css';
class AddNewSeriesSearchResult extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
isNewAddSeriesModalOpen: false
};
}
componentDidUpdate(prevProps) {
if (!prevProps.isExistingSeries && this.props.isExistingSeries) {
this.onAddSeriesModalClose();
2018-01-13 02:01:27 +00:00
}
}
//
// Listeners
onPress = () => {
this.setState({ isNewAddSeriesModalOpen: true });
}
onAddSeriesModalClose = () => {
2018-01-13 02:01:27 +00:00
this.setState({ isNewAddSeriesModalOpen: false });
}
onTVDBLinkPress = (event) => {
event.stopPropagation();
}
2018-01-13 02:01:27 +00:00
//
// Render
render() {
const {
tvdbId,
title,
titleSlug,
year,
network,
status,
overview,
statistics,
ratings,
folder,
seriesType,
2018-01-13 02:01:27 +00:00
images,
isExistingSeries,
isSmallScreen
} = this.props;
const seasonCount = statistics.seasonCount;
const {
isNewAddSeriesModalOpen
} = this.state;
const linkProps = isExistingSeries ? { to: `/series/${titleSlug}` } : { onPress: this.onPress };
let seasons = '1 Season';
if (seasonCount > 1) {
seasons = `${seasonCount} Seasons`;
}
return (
<div className={styles.searchResult}>
2018-01-13 02:01:27 +00:00
<Link
className={styles.underlay}
2018-01-13 02:01:27 +00:00
{...linkProps}
/>
<div className={styles.overlay}>
2018-01-13 02:01:27 +00:00
{
isSmallScreen ?
null :
<SeriesPoster
className={styles.poster}
images={images}
size={250}
overflow={true}
/>
2018-01-13 02:01:27 +00:00
}
<div className={styles.content}>
<div className={styles.titleRow}>
<div className={styles.titleContainer}>
<div className={styles.title}>
{title}
{
!title.contains(year) && year ?
<span className={styles.year}>
2020-10-04 19:16:42 +00:00
({year})
</span> :
null
}
</div>
</div>
<div className={styles.icons}>
{
isExistingSeries ?
<Icon
className={styles.alreadyExistsIcon}
name={icons.CHECK_CIRCLE}
size={36}
title="Already in your library"
/> :
null
}
<Link
className={styles.tvdbLink}
to={`http://www.thetvdb.com/?tab=series&id=${tvdbId}`}
onPress={this.onTVDBLinkPress}
>
<Icon
className={styles.tvdbLinkIcon}
name={icons.EXTERNAL_LINK}
size={28}
/>
</Link>
</div>
2018-01-13 02:01:27 +00:00
</div>
<div>
<Label size={sizes.LARGE}>
<HeartRating
rating={ratings.value}
iconSize={13}
/>
</Label>
{
network ?
<Label size={sizes.LARGE}>
{network}
</Label> :
null
2018-01-13 02:01:27 +00:00
}
{
seasonCount ?
<Label size={sizes.LARGE}>
{seasons}
</Label> :
null
2018-01-13 02:01:27 +00:00
}
{
status === 'ended' ?
<Label
kind={kinds.DANGER}
size={sizes.LARGE}
>
2020-10-04 19:16:42 +00:00
Ended
</Label> :
null
2018-01-13 02:01:27 +00:00
}
2020-01-12 20:09:58 +00:00
{
status === 'upcoming' ?
<Label
kind={kinds.INFO}
size={sizes.LARGE}
>
2020-10-04 19:16:42 +00:00
Upcoming
2020-01-12 20:09:58 +00:00
</Label> :
null
}
2018-01-13 02:01:27 +00:00
</div>
<div className={styles.overview}>
{overview}
</div>
</div>
</div>
2018-01-13 02:01:27 +00:00
<AddNewSeriesModal
isOpen={isNewAddSeriesModalOpen && !isExistingSeries}
tvdbId={tvdbId}
title={title}
year={year}
overview={overview}
folder={folder}
initialSeriesType={seriesType}
2018-01-13 02:01:27 +00:00
images={images}
onModalClose={this.onAddSeriesModalClose}
2018-01-13 02:01:27 +00:00
/>
</div>
);
}
}
AddNewSeriesSearchResult.propTypes = {
tvdbId: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
titleSlug: PropTypes.string.isRequired,
year: PropTypes.number.isRequired,
network: PropTypes.string,
status: PropTypes.string.isRequired,
overview: PropTypes.string,
statistics: PropTypes.object.isRequired,
ratings: PropTypes.object.isRequired,
folder: PropTypes.string.isRequired,
seriesType: PropTypes.string.isRequired,
2018-01-13 02:01:27 +00:00
images: PropTypes.arrayOf(PropTypes.object).isRequired,
isExistingSeries: PropTypes.bool.isRequired,
isSmallScreen: PropTypes.bool.isRequired
};
export default AddNewSeriesSearchResult;