diff --git a/src/public/js/actions/actionCreators.js b/src/public/js/actions/actionCreators.js index 67e63ad..8fe7a77 100644 --- a/src/public/js/actions/actionCreators.js +++ b/src/public/js/actions/actionCreators.js @@ -188,6 +188,43 @@ export function fetchShowDetails(imdbId) { ) } +export function addShowToWishlist(imdbId, season = null, episode = null) { + return request( + 'SHOW_ADD_TO_WISHLIST', + configureAxios().post(`/wishlist/shows/${imdbId}`, { + season: season, + episode: episode, + }), + [ + addAlertOk("Show added to the wishlist"), + updateShowWishlistStore(imdbId, true, season, episode), + ], + ) +} + +export function deleteShowFromWishlist(imdbId) { + return request( + 'SHOW_DELETE_FROM_WISHLIST', + configureAxios().delete(`/wishlist/shows/${imdbId}`), + [ + addAlertOk("Show deleted from the wishlist"), + updateShowWishlistStore(imdbId, false), + ], + ) +} + +export function updateShowWishlistStore(imdbId, wishlisted, season = null, episode = null) { + return { + type: 'SHOW_UPDATE_STORE_WISHLIST', + payload: { + wishlisted: wishlisted, + imdbId, + season, + episode, + } + } +} + export function selectShow(imdbId) { return { type: 'SELECT_SHOW', diff --git a/src/public/js/components/buttons/actions.js b/src/public/js/components/buttons/actions.js index 284ec5f..eecf765 100644 --- a/src/public/js/components/buttons/actions.js +++ b/src/public/js/components/buttons/actions.js @@ -10,9 +10,9 @@ export class WishlistButton extends React.Component { handleClick(e) { e.preventDefault(); if (this.props.wishlisted) { - this.props.deleteFromWishlist(this.props.movieId); + this.props.deleteFromWishlist(this.props.resourceId); } else { - this.props.addToWishlist(this.props.movieId); + this.props.addToWishlist(this.props.resourceId); } } render() { diff --git a/src/public/js/components/movies/actions.js b/src/public/js/components/movies/actions.js index e962268..bc61e4d 100644 --- a/src/public/js/components/movies/actions.js +++ b/src/public/js/components/movies/actions.js @@ -19,7 +19,7 @@ export default function ActionsButton(props) { /> } - - IMDB - - - Details - - - ); -} +import ShowButtons from './listButtons' export default class ShowList extends React.Component { componentWillMount() { @@ -68,7 +54,11 @@ export default class ShowList extends React.Component { /> {selectedShow && - + } diff --git a/src/public/js/components/shows/listButtons.js b/src/public/js/components/shows/listButtons.js new file mode 100644 index 0000000..d7baed3 --- /dev/null +++ b/src/public/js/components/shows/listButtons.js @@ -0,0 +1,39 @@ +import React from 'react' + +import { Link } from 'react-router' +import { DropdownButton } from 'react-bootstrap' + +import { WishlistButton } from '../buttons/actions' + +export default function ShowButtons(props) { + const imdbLink = `http://www.imdb.com/title/${props.show.imdb_id}`; + return ( +
+ + + IMDB + + + Details + +
+ ); +} + +function ActionsButton(props) { + let wishlisted = (props.show.tracked_season !== null && props.show.tracked_episode !== null); + return ( + + + + ); +} diff --git a/src/public/js/reducers/movies.js b/src/public/js/reducers/movies.js index 44aa015..408967d 100644 --- a/src/public/js/reducers/movies.js +++ b/src/public/js/reducers/movies.js @@ -46,7 +46,6 @@ export default function movieStore(state = defaultState, action) { case 'MOVIE_UPDATE_STORE_WISHLIST': return Object.assign({}, state, { movies: updateStoreWishlist(state.movies.slice(), action.payload.imdbId, action.payload.wishlisted), - fetchingDetails: false, }) case 'DELETE_MOVIE': return Object.assign({}, state, { diff --git a/src/public/js/reducers/shows.js b/src/public/js/reducers/shows.js index e18b4b5..bc32e30 100644 --- a/src/public/js/reducers/shows.js +++ b/src/public/js/reducers/shows.js @@ -45,6 +45,10 @@ export default function showStore(state = defaultState, action) { shows: action.payload.data, loading: false, }) + case 'SHOW_UPDATE_STORE_WISHLIST': + return Object.assign({}, state, { + shows: updateStoreWishlist(state.shows.slice(), action.payload), + }) case 'SELECT_SHOW': // Don't select the show if we're fetching another show's details if (state.fetchingDetails) { @@ -102,3 +106,20 @@ function sortEpisodes(show) { return show; } + +function updateStoreWishlist(shows, payload) { + let index = shows.map((el) => el.imdb_id).indexOf(payload.imdbId); + let season = payload.season; + let episode = payload.episode; + if (payload.wishlisted) { + if (season === null) { + season = 0; + } + if (episode === null) { + episode = 0; + } + } + shows[index].tracked_season = season; + shows[index].tracked_episode = episode; + return shows +}