Let the show fetch its own details

This commit is contained in:
Grégoire Delattre 2020-04-02 20:04:13 +02:00
parent 5f7d402614
commit 834ee8bcfc
3 changed files with 17 additions and 29 deletions

View File

@ -81,11 +81,7 @@ const App = () => (
exact exact
component={ShowList} component={ShowList}
/> />
<ShowsRoute <Route path="/shows/details/:imdbId" exact component={ShowDetails} />
path="/shows/details/:imdbId"
exact
component={ShowDetails}
/>
<Route render={() => <Redirect to="/movies/explore/yts/seeds" />} /> <Route render={() => <Redirect to="/movies/explore/yts/seeds" />} />
</Switch> </Switch>
</Container> </Container>

View File

@ -1,7 +1,6 @@
import React from "react"; import React, { useEffect } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Map } from "immutable"; import { useSelector, useDispatch } from "react-redux";
import { connect } from "react-redux";
import Loader from "../loader/loader"; import Loader from "../loader/loader";
@ -9,12 +8,17 @@ import { Fanart } from "./details/fanart";
import { Header } from "./details/header"; import { Header } from "./details/header";
import { SeasonsList } from "./details/seasons"; import { SeasonsList } from "./details/seasons";
const mapStateToProps = (state) => ({ import { fetchShowDetails } from "../../actions/shows";
loading: state.showStore.get("loading"),
show: state.showStore.get("show"), export const ShowDetails = ({ match }) => {
}); const dispatch = useDispatch();
const loading = useSelector((state) => state.showStore.get("loading"));
const show = useSelector((state) => state.showStore.get("show"));
useEffect(() => {
dispatch(fetchShowDetails(match.params.imdbId));
}, [dispatch, match]);
const showDetails = ({ show, loading }) => {
if (loading === true) { if (loading === true) {
return <Loader />; return <Loader />;
} }
@ -29,8 +33,6 @@ const showDetails = ({ show, loading }) => {
</React.Fragment> </React.Fragment>
); );
}; };
showDetails.propTypes = { ShowDetails.propTypes = {
loading: PropTypes.bool, match: PropTypes.object.isRequired,
show: PropTypes.instanceOf(Map),
}; };
export const ShowDetails = connect(mapStateToProps)(showDetails);

View File

@ -2,14 +2,9 @@ import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Route } from "react-router-dom"; import { Route } from "react-router-dom";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { fetchShows, fetchShowDetails } from "../../actions/shows"; import { fetchShows } from "../../actions/shows";
const ShowsRoute = ({ const ShowsRoute = ({ component: Component, fetchShows, ...otherProps }) => {
component: Component,
fetchShows,
fetchShowDetails,
...otherProps
}) => {
return ( return (
<Route <Route
{...otherProps} {...otherProps}
@ -32,9 +27,6 @@ const ShowsRoute = ({
"&category=" + "&category=" +
encodeURI(props.match.params.category); encodeURI(props.match.params.category);
break; break;
case "/shows/details/:imdbId":
fetchShowDetails(props.match.params.imdbId);
fetchUrl = "";
} }
if (fetchUrl != "") { if (fetchUrl != "") {
@ -50,10 +42,8 @@ ShowsRoute.propTypes = {
component: PropTypes.object, component: PropTypes.object,
match: PropTypes.object, match: PropTypes.object,
fetchShows: PropTypes.func.isRequired, fetchShows: PropTypes.func.isRequired,
fetchShowDetails: PropTypes.func.isRequired,
}; };
export default connect(null, { export default connect(null, {
fetchShows, fetchShows,
fetchShowDetails,
})(ShowsRoute); })(ShowsRoute);