Grégoire Delattre 114f022b8d
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Fix empty torrents returned as array in show episodes
The show episodes can handle undefined values themselves.
2020-04-10 17:09:43 +02:00

45 lines
1.2 KiB
JavaScript

import React from "react";
import PropTypes from "prop-types";
import { useDispatch, useSelector } from "react-redux";
import { getEpisodeDetails } from "../../../actions/shows";
import { TorrentsButton } from "../../buttons/torrents";
import { prettyEpisodeName } from "../../../utils";
export const EpisodeTorrentsButton = ({ season, episode }) => {
const dispatch = useDispatch();
const imdbId = useSelector((state) => state.show.show.imdb_id);
const search = () => {
dispatch(getEpisodeDetails(imdbId, season, episode));
};
const searching = useSelector((state) =>
state.show.show.seasons.get(season).get(episode).fetching
? state.show.show.seasons.get(season).get(episode).fetching
: false
);
const torrents = useSelector(
(state) => state.show.show.seasons.get(season).get(episode).torrents
);
const url = useSelector(
(state) =>
"#/torrents/search/shows/" +
encodeURI(prettyEpisodeName(state.show.show.title, season, episode))
);
return (
<TorrentsButton
torrents={torrents}
searching={searching}
search={search}
url={url}
/>
);
};
EpisodeTorrentsButton.propTypes = {
episode: PropTypes.number.isRequired,
season: PropTypes.number.isRequired,
};