diff --git a/src/public/js/components/shows/details.js b/src/public/js/components/shows/details.js index 114eb9d..2f6d6e9 100644 --- a/src/public/js/components/shows/details.js +++ b/src/public/js/components/shows/details.js @@ -1,6 +1,8 @@ import React from 'react' import Loader from '../loader/loader' +import { OverlayTrigger, Tooltip } from 'react-bootstrap' + export default class ShowDetails extends React.Component { componentWillMount() { this.props.fetchShowDetails(this.props.params.imdbId); @@ -12,10 +14,15 @@ export default class ShowDetails extends React.Component { } return (
-
+
); @@ -28,7 +35,11 @@ function Header(props){
- +
@@ -64,6 +75,11 @@ function HeaderDetails(props){
Rating
{props.data.rating}
+ ); } @@ -77,6 +93,7 @@ function SeasonsList(props){ ) @@ -120,6 +137,7 @@ class Season extends React.Component { key={key} data={episode} addTorrent={this.props.addTorrent} + addToWishlist={this.props.addToWishlist} /> ) }, this)} @@ -134,9 +152,15 @@ class Season extends React.Component { function Episode(props) { return ( - {props.data.episode} - {props.data.title} - + + + {props.data.episode} + + {props.data.title} + {props.data.torrents && props.data.torrents.map(function(torrent, index) { let key = `${props.data.season}-${props.data.episode}-${torrent.source}-${torrent.quality}`; @@ -178,13 +202,95 @@ class Torrent extends React.Component { } } +class TrackHeader extends React.Component { + constructor(props) { + super(props); + this.handleClick = this.handleClick.bind(this); + } + handleClick(e, url) { + e.preventDefault(); + let wishlisted = (this.props.data.tracked_season !== null && this.props.data.tracked_episode !== null); + if (wishlisted) { + this.props.deleteFromWishlist(this.props.data.imdb_id); + } else { + this.props.addToWishlist(this.props.data.imdb_id); + } + } + render() { + let wishlisted = (this.props.data.tracked_season !== null && this.props.data.tracked_episode !== null); + if (wishlisted) { + let msg; + if (this.props.data.tracked_season !== 0 && this.props.data.tracked_episode !== 0) { + msg = ( +
+ Show tracked from season {this.props.data.tracked_season} episode {this.props.data.tracked_episode} +
+ ); + } 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(); + this.props.addToWishlist(this.props.data.show_imdb_id, this.props.data.season, this.props.data.episode); + } + render() { + const tooltipId = `tooltip-${this.props.data.season}-${this.props.data.episode}`; + const tooltip = ( + Track show from here + ); + return ( + + this.handleClick(e)}> + + + + ); + } +} + function DownloadButton(props) { if (props.data.polochon_url === "") { return null } return ( - + Download diff --git a/src/public/js/reducers/shows.js b/src/public/js/reducers/shows.js index bc32e30..5d940fc 100644 --- a/src/public/js/reducers/shows.js +++ b/src/public/js/reducers/shows.js @@ -47,7 +47,8 @@ export default function showStore(state = defaultState, action) { }) case 'SHOW_UPDATE_STORE_WISHLIST': return Object.assign({}, state, { - shows: updateStoreWishlist(state.shows.slice(), action.payload), + shows: updateShowsStoreWishlist(state.shows.slice(), action.payload), + show: updateShowStoreWishlist(Object.assign({}, state.show), action.payload), }) case 'SELECT_SHOW': // Don't select the show if we're fetching another show's details @@ -107,7 +108,12 @@ function sortEpisodes(show) { return show; } -function updateStoreWishlist(shows, payload) { +// Update the store containing all the shows +function updateShowsStoreWishlist(shows, payload) { + if (shows.length === 0) { + return shows; + } + let index = shows.map((el) => el.imdb_id).indexOf(payload.imdbId); let season = payload.season; let episode = payload.episode; @@ -123,3 +129,23 @@ function updateStoreWishlist(shows, payload) { shows[index].tracked_episode = episode; return shows } + +// Update the store containing the current detailed show +function updateShowStoreWishlist(show, payload) { + if (show.seasons.length === 0) { + return show; + } + let season = payload.season; + let episode = payload.episode; + if (payload.wishlisted) { + if (season === null) { + season = 0; + } + if (episode === null) { + episode = 0; + } + } + show.tracked_season = season; + show.tracked_episode = episode; + return show +}