import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { toJS } from 'immutable'
import { addTorrent } from '../../actions/torrents'
import { refreshSubtitles } from '../../actions/subtitles'
import { addShowToWishlist, deleteShowFromWishlist, getEpisodeDetails, updateShowDetails } from '../../actions/shows'
import Loader from '../loader/loader'
import DownloadButton from '../buttons/download'
import SubtitlesButton from '../buttons/subtitles'
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
function mapStateToProps(state) {
return {
loading: state.showStore.loading,
show: state.showStore.get('show'),
};
}
const mapDispatchToProps = (dispatch) =>
bindActionCreators({addTorrent, addShowToWishlist, deleteShowFromWishlist,
updateShowDetails, getEpisodeDetails,
refreshSubtitles }, dispatch)
class ShowDetails extends React.Component {
render() {
// Loading
if (this.props.loading) {
return ();
}
return (
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(ShowDetails);
function Header(props){
return (
);
}
function HeaderThumbnail(props){
return (
);
}
function HeaderDetails(props){
const imdbLink = `http://www.imdb.com/title/${props.data.get('imdb_id')}`;
return (
- Title
- {props.data.get('title')}
- Plot
- {props.data.get('plot')}
- IMDB
-
Open in IMDB
- Year
- {props.data.get('year')}
- Rating
- {props.data.get('rating')}
);
}
function SeasonsList(props){
return (
{props.data.get('seasons').entrySeq().map(function([season, data]) {
return (
);
})}
)
}
class Season extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
this.state = { colapsed: true };
}
handleClick(e) {
e.preventDefault();
this.setState({ colapsed: !this.state.colapsed });
}
render() {
return (
this.handleClick(e)}>
Season {this.props.season}
— ({this.props.data.toList().size} episodes)
{this.state.colapsed ||
}
{this.state.colapsed &&
}
{this.state.colapsed ||
{this.props.data.toList().map(function(episode) {
let key = `${episode.get('season')}-${episode.get('episode')}`;
return (
)
}, this)}
}
)
}
}
function Episode(props) {
// TODO: remove this when everything uses immutable
let subtitles;
if (props.data.has('subtitles') && props.data.get('subtitles')) {
subtitles = props.data.get('subtitles').toJS();
}
return (
{props.data.get('episode')}
|
{props.data.get('title')}
{props.data.get('torrents') && props.data.get('torrents').toList().map(function(torrent) {
let key = `${props.data.get('season')}-${props.data.get('episode')}-${torrent.get('source')}-${torrent.get('quality')}`;
return (
)
})}
|
)
}
class Torrent extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e, url) {
e.preventDefault();
this.props.addTorrent(url);
}
render() {
return (
this.handleClick(e, this.props.data.get('url'))}
href={this.props.data.url} >
{this.props.data.get('quality')}
)
}
}
class TrackHeader extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e, url) {
e.preventDefault();
const trackedSeason = this.props.data.get('tracked_season');
const trackedEpisode = this.props.data.get('tracked_episode');
const imdbId = this.props.data.get('imdb_id');
const wishlisted = (trackedSeason !== null && trackedEpisode !== null);
if (wishlisted) {
this.props.deleteFromWishlist(imdbId);
} else {
this.props.addToWishlist(imdbId);
}
}
render() {
const trackedSeason = this.props.data.get('tracked_season');
const trackedEpisode = this.props.data.get('tracked_episode');
const imdbId = this.props.data.get('imdb_id');
const wishlisted = (trackedSeason !== null && trackedEpisode !== null);
let msg;
if (wishlisted) {
if (trackedSeason !== 0 && trackedEpisode !== 0) {
msg = (
Show tracked from season {trackedSeason} episode {trackedEpisode}
);
} else {
msg = (
Whole show tracked
);
}
return (
- Tracking active
{msg}
-
this.handleClick(e)}>
Untrack the show
);
} else {
return (
- Tracking inactive
-
this.handleClick(e)}>
Track the whole show
);
}
}
}
class TrackButton extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e, url) {
e.preventDefault();
const imdbId = this.props.data.get('show_imdb_id');
const season = this.props.data.get('season');
const episode = this.props.data.get('episode');
this.props.addToWishlist(imdbId, season, episode);
}
render() {
const tooltipId = `tooltip-${this.props.data.season}-${this.props.data.episode}`;
const tooltip = (
Track show from here
);
return (
this.handleClick(e)}>
);
}
}
class GetDetailsButton extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e, url) {
e.preventDefault();
if (this.props.data.get('fetching')) {
return
}
const imdbId = this.props.data.get('show_imdb_id');
const season = this.props.data.get('season');
const episode = this.props.data.get('episode');
this.props.getEpisodeDetails(imdbId, season, episode);
}
render() {
return (
this.handleClick(e)}>
{this.props.data.get('fetching') ||
Refresh
}
{this.props.data.get('fetching') &&
Refreshing
}
);
}
}