Grégoire Delattre 4b26080193
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Update redux state management
Use immer with native javascript objects instead of immutablejs.
2020-04-07 18:22:26 +02:00

47 lines
1.3 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
? 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,
};