Add a button to refresh a show #41
21
frontend/js/components/buttons/refresh.js
Normal file
21
frontend/js/components/buttons/refresh.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import React from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
export const Refresh = ({ onClick, loading, kind }) => {
|
||||||
|
return (
|
||||||
|
<button onClick={onClick} className={`btn btn-${kind} btn-sm w-md-100 m-1`}>
|
||||||
|
<i className={`fa ${loading ? "fa-spin" : ""} fa-refresh mr-1`} />
|
||||||
|
Refresh
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
Refresh.propTypes = {
|
||||||
|
onClick: PropTypes.func.isRequired,
|
||||||
|
loading: PropTypes.bool.isRequired,
|
||||||
|
kind: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
Refresh.defaultProps = {
|
||||||
|
onClick: () => {},
|
||||||
|
loading: false,
|
||||||
|
kind: "secondary",
|
||||||
|
};
|
@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
import { Plot } from "../../details/plot";
|
import { Plot } from "../../details/plot";
|
||||||
@ -8,27 +8,35 @@ import { Title } from "../../details/title";
|
|||||||
import { TrackingLabel } from "../../details/tracking";
|
import { TrackingLabel } from "../../details/tracking";
|
||||||
|
|
||||||
import { ImdbBadge } from "../../buttons/imdb";
|
import { ImdbBadge } from "../../buttons/imdb";
|
||||||
|
import { Refresh } from "../../buttons/refresh";
|
||||||
|
|
||||||
import { showWishlistToggle } from "../../../actions/shows";
|
import {
|
||||||
|
showWishlistToggle,
|
||||||
|
fetchShowDetails,
|
||||||
|
getShowDetails,
|
||||||
|
} from "../../../actions/shows";
|
||||||
|
|
||||||
export const Header = () => {
|
export const Header = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const posterUrl = useSelector((state) => state.show.show.poster_url);
|
const {
|
||||||
const title = useSelector((state) => state.show.show.title);
|
poster_url: posterUrl,
|
||||||
const imdbId = useSelector((state) => state.show.show.imdb_id);
|
title,
|
||||||
const year = useSelector((state) => state.show.show.year);
|
imdb_id: imdbId,
|
||||||
const rating = useSelector((state) => state.show.show.rating);
|
year,
|
||||||
const plot = useSelector((state) => state.show.show.plot);
|
rating,
|
||||||
|
plot,
|
||||||
|
tracked_season: trackedSeason,
|
||||||
|
tracked_episode: trackedEpisode,
|
||||||
|
fetchingDetails,
|
||||||
|
} = useSelector((state) => state.show.show);
|
||||||
|
|
||||||
const trackedSeason = useSelector((state) => state.show.show.tracked_season);
|
useEffect(() => {
|
||||||
const trackedEpisode = useSelector(
|
if (fetchingDetails === false) {
|
||||||
(state) => state.show.show.tracked_episode
|
dispatch(fetchShowDetails(imdbId));
|
||||||
);
|
}
|
||||||
const wishlisted = useSelector(
|
}, [fetchingDetails, imdbId, dispatch]);
|
||||||
(state) =>
|
|
||||||
state.show.show.tracked_season !== null &&
|
const wishlisted = trackedSeason !== null && trackedEpisode !== null;
|
||||||
state.show.show.tracked_episode !== null
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card col-12 col-md-10 offset-md-1 mt-n3 mb-3">
|
<div className="card col-12 col-md-10 offset-md-1 mt-n3 mb-3">
|
||||||
@ -55,6 +63,11 @@ export const Header = () => {
|
|||||||
</p>
|
</p>
|
||||||
<p className="card-text">
|
<p className="card-text">
|
||||||
<ImdbBadge imdbId={imdbId} />
|
<ImdbBadge imdbId={imdbId} />
|
||||||
|
<Refresh
|
||||||
|
onClick={() => dispatch(getShowDetails(imdbId))}
|
||||||
|
loading={fetchingDetails}
|
||||||
|
kind="info"
|
||||||
|
/>
|
||||||
</p>
|
</p>
|
||||||
<p className="card-text">
|
<p className="card-text">
|
||||||
<TrackingLabel
|
<TrackingLabel
|
||||||
|
@ -7,10 +7,12 @@ import {
|
|||||||
selectShow,
|
selectShow,
|
||||||
showWishlistToggle,
|
showWishlistToggle,
|
||||||
getShowExploreOptions,
|
getShowExploreOptions,
|
||||||
|
getShowDetails,
|
||||||
} from "../../actions/shows";
|
} from "../../actions/shows";
|
||||||
|
|
||||||
import ListDetails from "../list/details";
|
import ListDetails from "../list/details";
|
||||||
import ListPosters from "../list/posters";
|
import ListPosters from "../list/posters";
|
||||||
|
import { Refresh } from "../buttons/refresh";
|
||||||
|
|
||||||
const fetchUrl = (match) => {
|
const fetchUrl = (match) => {
|
||||||
switch (match.path) {
|
switch (match.path) {
|
||||||
@ -92,11 +94,15 @@ const ShowList = ({ match, history }) => {
|
|||||||
<span>
|
<span>
|
||||||
<button
|
<button
|
||||||
onClick={() => showDetails(selectedShow.imdb_id)}
|
onClick={() => showDetails(selectedShow.imdb_id)}
|
||||||
className="btn btn-primary btn-sm w-md-100"
|
className="btn btn-primary btn-sm w-md-100 m-1"
|
||||||
>
|
>
|
||||||
<i className="fa fa-external-link mr-1" />
|
<i className="fa fa-external-link mr-1" />
|
||||||
Details
|
Details
|
||||||
</button>
|
</button>
|
||||||
|
<Refresh
|
||||||
|
onClick={() => dispatch(getShowDetails(selectedShow.imdb_id))}
|
||||||
|
loading={selectedShow.fetchingDetails}
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
</ListDetails>
|
</ListDetails>
|
||||||
</div>
|
</div>
|
||||||
|
@ -68,6 +68,14 @@ export default (state = defaultState, action) =>
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "SHOW_GET_DETAILS_PENDING":
|
||||||
|
draft.show.fetchingDetails = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "SHOW_GET_DETAILS_FULFILLED":
|
||||||
|
draft.show.fetchingDetails = false;
|
||||||
|
break;
|
||||||
|
|
||||||
case "SHOW_UPDATE_STORE_WISHLIST":
|
case "SHOW_UPDATE_STORE_WISHLIST":
|
||||||
// TODO: check with we give the imdb in the payload
|
// TODO: check with we give the imdb in the payload
|
||||||
draft.show.tracked_season = action.payload.season; // eslint-disable-line camelcase
|
draft.show.tracked_season = action.payload.season; // eslint-disable-line camelcase
|
||||||
|
@ -46,7 +46,9 @@ export default (state = defaultState, action) =>
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "SHOW_GET_DETAILS_PENDING":
|
case "SHOW_GET_DETAILS_PENDING":
|
||||||
|
if (draft.shows.get(action.payload.main.imdbId)) {
|
||||||
draft.shows.get(action.payload.main.imdbId).fetchingDetails = true;
|
draft.shows.get(action.payload.main.imdbId).fetchingDetails = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SHOW_GET_DETAILS_FULFILLED":
|
case "SHOW_GET_DETAILS_FULFILLED":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user