diff --git a/src/internal/shows/handlers.go b/src/internal/shows/handlers.go index df156c9..56f5909 100644 --- a/src/internal/shows/handlers.go +++ b/src/internal/shows/handlers.go @@ -10,6 +10,7 @@ import ( "strconv" "github.com/gorilla/mux" + customError "github.com/odwrtw/errors" "github.com/odwrtw/papi" polochon "github.com/odwrtw/polochon/lib" "github.com/odwrtw/polochon/modules/pam" @@ -311,7 +312,8 @@ func EpisodeDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request, return env.RenderError(w, err) } - if err := e.GetTorrents(env, force); err != nil { + err = e.GetTorrents(env, force) + if err != nil && customError.IsFatal(err) { return env.RenderError(w, err) } diff --git a/src/public/js/actions/actionCreators.js b/src/public/js/actions/actionCreators.js index 1f4591d..0ef97ca 100644 --- a/src/public/js/actions/actionCreators.js +++ b/src/public/js/actions/actionCreators.js @@ -181,6 +181,32 @@ export function searchShows(search) { ) } +export function getShowDetails(imdbId) { + return request( + 'SHOW_GET_DETAILS', + configureAxios().post(`/shows/${imdbId}/refresh`) + ) +} + + +export function getEpisodeDetails(imdbId, season, episode) { + return request( + 'EPISODE_GET_DETAILS', + configureAxios().post(`/shows/${imdbId}/seasons/${season}/episodes/${episode}`), + ) +} + +export function updateEpisodeDetailsStore(imdbId, season, episode) { + return { + type: 'EPISODE_GET_DETAILS', + payload: { + imdbId, + season, + episode, + }, + } +} + export function fetchShowDetails(imdbId) { return request( 'SHOW_FETCH_DETAILS', diff --git a/src/public/js/components/list/posters.js b/src/public/js/components/list/posters.js index f8d4db1..bb80d20 100644 --- a/src/public/js/components/list/posters.js +++ b/src/public/js/components/list/posters.js @@ -65,6 +65,7 @@ export default class ListPosters extends React.Component { {elmts.map(function(el, index) { const selected = (el.imdb_id === this.props.selectedImdbId) ? true : false; diff --git a/src/public/js/components/shows/details.js b/src/public/js/components/shows/details.js index 3a125dd..e011a88 100644 --- a/src/public/js/components/shows/details.js +++ b/src/public/js/components/shows/details.js @@ -23,6 +23,8 @@ export default class ShowDetails extends React.Component { data={this.props.showStore.show} addTorrent={this.props.addTorrent} addToWishlist={this.props.addShowToWishlist} + getEpisodeDetails={this.props.getEpisodeDetails} + updateEpisodeDetailsStore={this.props.updateEpisodeDetailsStore} /> ); @@ -94,6 +96,8 @@ function SeasonsList(props){ data={season} addTorrent={props.addTorrent} addToWishlist={props.addToWishlist} + getEpisodeDetails={props.getEpisodeDetails} + updateEpisodeDetailsStore={props.updateEpisodeDetailsStore} /> ) @@ -138,6 +142,8 @@ class Season extends React.Component { data={episode} addTorrent={this.props.addTorrent} addToWishlist={this.props.addToWishlist} + getEpisodeDetails={this.props.getEpisodeDetails} + updateEpisodeDetailsStore={this.props.updateEpisodeDetailsStore} /> ) }, this)} @@ -173,6 +179,11 @@ function Episode(props) { ) })} + @@ -297,3 +308,36 @@ function DownloadButton(props) { ); } + +class GetDetailsButton extends React.Component { + constructor(props) { + super(props); + this.handleClick = this.handleClick.bind(this); + } + handleClick(e, url) { + e.preventDefault(); + if (this.props.data.fetching) { + return + } + this.props.updateEpisodeDetailsStore(this.props.data.show_imdb_id, this.props.data.season, this.props.data.episode); + this.props.getEpisodeDetails(this.props.data.show_imdb_id, this.props.data.season, this.props.data.episode); + } + render() { + return ( + + this.handleClick(e)}> + {this.props.data.fetching || + + Refresh + + } + {this.props.data.fetching && + + Refreshing + + } + + + ); + } +} diff --git a/src/public/js/components/shows/list.js b/src/public/js/components/shows/list.js index 3704260..dce38bb 100644 --- a/src/public/js/components/shows/list.js +++ b/src/public/js/components/shows/list.js @@ -58,6 +58,8 @@ export default class ShowList extends React.Component { show={selectedShow} deleteFromWishlist={this.props.deleteShowFromWishlist} addToWishlist={this.props.addShowToWishlist} + getDetails={this.props.getShowDetails} + fetching={this.props.showStore.getDetails} /> } diff --git a/src/public/js/components/shows/listButtons.js b/src/public/js/components/shows/listButtons.js index d7baed3..34ec5ed 100644 --- a/src/public/js/components/shows/listButtons.js +++ b/src/public/js/components/shows/listButtons.js @@ -3,7 +3,7 @@ import React from 'react' import { Link } from 'react-router' import { DropdownButton } from 'react-bootstrap' -import { WishlistButton } from '../buttons/actions' +import { WishlistButton, RefreshButton } from '../buttons/actions' export default function ShowButtons(props) { const imdbLink = `http://www.imdb.com/title/${props.show.imdb_id}`; @@ -13,6 +13,8 @@ export default function ShowButtons(props) { show={props.show} addToWishlist={props.addToWishlist} deleteFromWishlist={props.deleteFromWishlist} + getDetails={props.getDetails} + fetching={props.fetching} /> IMDB @@ -28,6 +30,11 @@ function ActionsButton(props) { let wishlisted = (props.show.tracked_season !== null && props.show.tracked_episode !== null); return ( + el.season).indexOf(data.season.toString()); + let episodeIndex = show.seasons[seasonIndex].episodes.map((el) => el.episode).indexOf(data.episode); + if ('id' in data) { + show.seasons[seasonIndex].episodes[episodeIndex] = data; + } + show.seasons[seasonIndex].episodes[episodeIndex].fetching = fetching; + return show +} + function sortEpisodes(show) { let episodes = show.episodes; delete show["episodes"]; @@ -75,6 +113,7 @@ function sortEpisodes(show) { // Extract the seasons let seasons = {}; for (let ep of episodes) { + ep.fetching = false; if (!seasons[ep.season]) { seasons[ep.season] = { episodes: [] }; } @@ -149,3 +188,9 @@ function updateShowStoreWishlist(show, payload) { show.tracked_episode = episode; return show } + +function updateShowDetails(shows, data) { + let index = shows.map((el) => el.imdb_id).indexOf(data.imdb_id); + shows[index] = data; + return shows +}