Use redux hooks on shows components
This commit is contained in:
parent
27f5c5d558
commit
d998d2838d
@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { Map } from "immutable";
|
import { Map } from "immutable";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
import { showWishlistToggle } from "../../../actions/shows";
|
import { showWishlistToggle } from "../../../actions/shows";
|
||||||
|
|
||||||
@ -24,12 +24,17 @@ import { EpisodeSubtitlesButton } from "./subtitlesButton";
|
|||||||
import { EpisodeThumb } from "./episodeThumb";
|
import { EpisodeThumb } from "./episodeThumb";
|
||||||
import { EpisodeTorrentsButton } from "./torrentsButton";
|
import { EpisodeTorrentsButton } from "./torrentsButton";
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
export const Episode = (props) => {
|
||||||
trackedSeason: state.showStore.getIn(["show", "tracked_season"], null),
|
const dispatch = useDispatch();
|
||||||
trackedEpisode: state.showStore.getIn(["show", "tracked_episode"], null),
|
|
||||||
});
|
|
||||||
|
|
||||||
const episode = (props) => (
|
const trackedSeason = useSelector((state) =>
|
||||||
|
state.showStore.getIn(["show", "tracked_season"], null)
|
||||||
|
);
|
||||||
|
const trackedEpisode = useSelector((state) =>
|
||||||
|
state.showStore.getIn(["show", "tracked_episode"], null)
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
<div className="d-flex flex-column flex-lg-row mb-3 pb-3 border-bottom border-light">
|
<div className="d-flex flex-column flex-lg-row mb-3 pb-3 border-bottom border-light">
|
||||||
<EpisodeThumb url={props.data.get("thumb")} />
|
<EpisodeThumb url={props.data.get("thumb")} />
|
||||||
<div className="d-flex flex-column">
|
<div className="d-flex flex-column">
|
||||||
@ -37,16 +42,18 @@ const episode = (props) => (
|
|||||||
title={`${props.data.get("episode")}. ${props.data.get("title")}`}
|
title={`${props.data.get("episode")}. ${props.data.get("title")}`}
|
||||||
wishlisted={isEpisodeWishlisted(
|
wishlisted={isEpisodeWishlisted(
|
||||||
props.data,
|
props.data,
|
||||||
props.trackedSeason,
|
trackedSeason,
|
||||||
props.trackedEpisode
|
trackedEpisode
|
||||||
)}
|
)}
|
||||||
wishlist={() =>
|
wishlist={() =>
|
||||||
props.showWishlistToggle(
|
dispatch(
|
||||||
|
showWishlistToggle(
|
||||||
isEpisodeWishlisted(props.data),
|
isEpisodeWishlisted(props.data),
|
||||||
props.data.get("show_imdb_id"),
|
props.data.get("show_imdb_id"),
|
||||||
props.data.get("season"),
|
props.data.get("season"),
|
||||||
props.data.get("episode")
|
props.data.get("episode")
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<ReleaseDate date={props.data.get("aired")} />
|
<ReleaseDate date={props.data.get("aired")} />
|
||||||
@ -96,15 +103,9 @@ const episode = (props) => (
|
|||||||
</ShowMore>
|
</ShowMore>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
episode.propTypes = {
|
};
|
||||||
data: PropTypes.instanceOf(Map).isRequired,
|
Episode.propTypes = {
|
||||||
trackedSeason: PropTypes.number,
|
data: PropTypes.instanceOf(Map).isRequired,
|
||||||
trackedEpisode: PropTypes.number,
|
showName: PropTypes.string.isRequired,
|
||||||
showName: PropTypes.string.isRequired,
|
|
||||||
showWishlistToggle: PropTypes.func,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Episode = connect(mapStateToProps, { showWishlistToggle })(
|
|
||||||
episode
|
|
||||||
);
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { Map } from "immutable";
|
import { Map } from "immutable";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import { isWishlisted } from "../../../utils";
|
import { isWishlisted } from "../../../utils";
|
||||||
|
|
||||||
@ -15,7 +15,9 @@ import { TrackingLabel } from "../../details/tracking";
|
|||||||
|
|
||||||
import { ImdbBadge } from "../../buttons/imdb";
|
import { ImdbBadge } from "../../buttons/imdb";
|
||||||
|
|
||||||
export const header = (props) => (
|
export const Header = (props) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
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">
|
||||||
<div className="d-flex flex-column flex-md-row">
|
<div className="d-flex flex-column flex-md-row">
|
||||||
<div className="d-flex justify-content-center">
|
<div className="d-flex justify-content-center">
|
||||||
@ -31,10 +33,12 @@ export const header = (props) => (
|
|||||||
title={props.data.get("title")}
|
title={props.data.get("title")}
|
||||||
wishlisted={isWishlisted(props.data)}
|
wishlisted={isWishlisted(props.data)}
|
||||||
wishlist={() =>
|
wishlist={() =>
|
||||||
props.showWishlistToggle(
|
dispatch(
|
||||||
|
showWishlistToggle(
|
||||||
isWishlisted(props.data),
|
isWishlisted(props.data),
|
||||||
props.data.get("imdb_id")
|
props.data.get("imdb_id")
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
@ -61,10 +65,8 @@ export const header = (props) => (
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
header.propTypes = {
|
};
|
||||||
data: PropTypes.instanceOf(Map),
|
Header.propTypes = {
|
||||||
showWishlistToggle: PropTypes.func,
|
data: PropTypes.instanceOf(Map),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Header = connect(null, { showWishlistToggle })(header);
|
|
||||||
|
@ -1,39 +1,37 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { List } from "immutable";
|
import { List } from "immutable";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import { searchEpisodeSubtitles } from "../../../actions/subtitles";
|
import { searchEpisodeSubtitles } from "../../../actions/subtitles";
|
||||||
|
|
||||||
import { SubtitlesButton } from "../../buttons/subtitles";
|
import { SubtitlesButton } from "../../buttons/subtitles";
|
||||||
|
|
||||||
const episodeSubtitlesButton = ({
|
export const EpisodeSubtitlesButton = ({
|
||||||
inLibrary,
|
inLibrary,
|
||||||
imdbId,
|
imdbId,
|
||||||
season,
|
season,
|
||||||
episode,
|
episode,
|
||||||
searching,
|
searching,
|
||||||
searchEpisodeSubtitles,
|
|
||||||
subtitles,
|
subtitles,
|
||||||
}) => (
|
}) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
return (
|
||||||
<SubtitlesButton
|
<SubtitlesButton
|
||||||
subtitles={subtitles}
|
subtitles={subtitles}
|
||||||
inLibrary={inLibrary}
|
inLibrary={inLibrary}
|
||||||
searching={searching}
|
searching={searching}
|
||||||
search={() => searchEpisodeSubtitles(imdbId, season, episode)}
|
search={() => dispatch(searchEpisodeSubtitles(imdbId, season, episode))}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
episodeSubtitlesButton.propTypes = {
|
EpisodeSubtitlesButton.propTypes = {
|
||||||
inLibrary: PropTypes.bool,
|
inLibrary: PropTypes.bool,
|
||||||
searching: PropTypes.bool,
|
searching: PropTypes.bool,
|
||||||
imdbId: PropTypes.string,
|
imdbId: PropTypes.string,
|
||||||
season: PropTypes.number,
|
season: PropTypes.number,
|
||||||
episode: PropTypes.number,
|
episode: PropTypes.number,
|
||||||
searchEpisodeSubtitles: PropTypes.func,
|
|
||||||
subtitles: PropTypes.instanceOf(List),
|
subtitles: PropTypes.instanceOf(List),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EpisodeSubtitlesButton = connect(null, { searchEpisodeSubtitles })(
|
|
||||||
episodeSubtitlesButton
|
|
||||||
);
|
|
||||||
|
@ -1,40 +1,39 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { List } from "immutable";
|
import { List } from "immutable";
|
||||||
|
|
||||||
import { getEpisodeDetails } from "../../../actions/shows";
|
import { getEpisodeDetails } from "../../../actions/shows";
|
||||||
|
|
||||||
import { TorrentsButton } from "../../buttons/torrents";
|
import { TorrentsButton } from "../../buttons/torrents";
|
||||||
import { prettyEpisodeName } from "../../../utils";
|
import { prettyEpisodeName } from "../../../utils";
|
||||||
|
|
||||||
const episodeTorrentsButton = ({
|
export const EpisodeTorrentsButton = ({
|
||||||
torrents,
|
torrents,
|
||||||
imdbId,
|
imdbId,
|
||||||
season,
|
season,
|
||||||
episode,
|
episode,
|
||||||
showName,
|
showName,
|
||||||
searching,
|
searching,
|
||||||
getEpisodeDetails,
|
}) => {
|
||||||
}) => (
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
return (
|
||||||
<TorrentsButton
|
<TorrentsButton
|
||||||
torrents={torrents}
|
torrents={torrents}
|
||||||
searching={searching}
|
searching={searching}
|
||||||
search={() => getEpisodeDetails(imdbId, season, episode)}
|
search={() => dispatch(getEpisodeDetails(imdbId, season, episode))}
|
||||||
url={`#/torrents/search/shows/${encodeURI(
|
url={`#/torrents/search/shows/${encodeURI(
|
||||||
prettyEpisodeName(showName, season, episode)
|
prettyEpisodeName(showName, season, episode)
|
||||||
)}`}
|
)}`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
episodeTorrentsButton.propTypes = {
|
};
|
||||||
|
EpisodeTorrentsButton.propTypes = {
|
||||||
torrents: PropTypes.instanceOf(List),
|
torrents: PropTypes.instanceOf(List),
|
||||||
showName: PropTypes.string.isRequired,
|
showName: PropTypes.string.isRequired,
|
||||||
imdbId: PropTypes.string.isRequired,
|
imdbId: PropTypes.string.isRequired,
|
||||||
episode: PropTypes.number.isRequired,
|
episode: PropTypes.number.isRequired,
|
||||||
season: PropTypes.number.isRequired,
|
season: PropTypes.number.isRequired,
|
||||||
searching: PropTypes.bool.isRequired,
|
searching: PropTypes.bool.isRequired,
|
||||||
getEpisodeDetails: PropTypes.func.isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EpisodeTorrentsButton = connect(null, { getEpisodeDetails })(
|
|
||||||
episodeTorrentsButton
|
|
||||||
);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user