60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
import React from "react";
|
|
import PropTypes from "prop-types";
|
|
import { Route } from "react-router-dom";
|
|
import { connect } from "react-redux";
|
|
import { fetchShows, fetchShowDetails } from "../../actions/shows";
|
|
|
|
const ShowsRoute = ({
|
|
component: Component,
|
|
fetchShows,
|
|
fetchShowDetails,
|
|
...otherProps
|
|
}) => {
|
|
return (
|
|
<Route
|
|
{...otherProps}
|
|
render={(props) => {
|
|
let fetchUrl = "";
|
|
switch (props.match.path) {
|
|
case "/shows/polochon":
|
|
fetchUrl = "/shows/polochon";
|
|
break;
|
|
case "/shows/wishlist":
|
|
fetchUrl = "/wishlist/shows";
|
|
break;
|
|
case "/shows/search/:search":
|
|
fetchUrl = "/shows/search/" + props.match.params.search;
|
|
break;
|
|
case "/shows/explore/:source/:category":
|
|
fetchUrl =
|
|
"/shows/explore?source=" +
|
|
encodeURI(props.match.params.source) +
|
|
"&category=" +
|
|
encodeURI(props.match.params.category);
|
|
break;
|
|
case "/shows/details/:imdbId":
|
|
fetchShowDetails(props.match.params.imdbId);
|
|
fetchUrl = "";
|
|
}
|
|
|
|
if (fetchUrl != "") {
|
|
fetchShows(fetchUrl);
|
|
}
|
|
|
|
return <Component {...props} />;
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
ShowsRoute.propTypes = {
|
|
component: PropTypes.object,
|
|
match: PropTypes.object,
|
|
fetchShows: PropTypes.func.isRequired,
|
|
fetchShowDetails: PropTypes.func.isRequired,
|
|
};
|
|
|
|
export default connect(null, {
|
|
fetchShows,
|
|
fetchShowDetails,
|
|
})(ShowsRoute);
|