Remove the custom routes for movies and shows
This commit is contained in:
parent
834ee8bcfc
commit
c5336c477a
@ -28,12 +28,10 @@ import { AdminPanel } from "./components/admins/panel";
|
|||||||
import { Notifications } from "./components/notifications/notifications";
|
import { Notifications } from "./components/notifications/notifications";
|
||||||
import Alert from "./components/alerts/alert";
|
import Alert from "./components/alerts/alert";
|
||||||
import MovieList from "./components/movies/list";
|
import MovieList from "./components/movies/list";
|
||||||
import MoviesRoute from "./components/movies/route";
|
|
||||||
import NavBar from "./components/navbar";
|
import NavBar from "./components/navbar";
|
||||||
import WsHandler from "./components/websocket";
|
import WsHandler from "./components/websocket";
|
||||||
import { ShowDetails } from "./components/shows/details";
|
import { ShowDetails } from "./components/shows/details";
|
||||||
import ShowList from "./components/shows/list";
|
import ShowList from "./components/shows/list";
|
||||||
import ShowsRoute from "./components/shows/route";
|
|
||||||
import TorrentList from "./components/torrents/list";
|
import TorrentList from "./components/torrents/list";
|
||||||
import TorrentSearch from "./components/torrents/search";
|
import TorrentSearch from "./components/torrents/search";
|
||||||
import UserActivation from "./components/users/activation";
|
import UserActivation from "./components/users/activation";
|
||||||
@ -61,22 +59,18 @@ const App = () => (
|
|||||||
exact
|
exact
|
||||||
component={TorrentSearch}
|
component={TorrentSearch}
|
||||||
/>
|
/>
|
||||||
<MoviesRoute path="/movies/polochon" exact component={MovieList} />
|
<Route path="/movies/polochon" exact component={MovieList} />
|
||||||
<MoviesRoute path="/movies/wishlist" exact component={MovieList} />
|
<Route path="/movies/wishlist" exact component={MovieList} />
|
||||||
<MoviesRoute
|
<Route path="/movies/search/:search" exact component={MovieList} />
|
||||||
path="/movies/search/:search"
|
<Route
|
||||||
exact
|
|
||||||
component={MovieList}
|
|
||||||
/>
|
|
||||||
<MoviesRoute
|
|
||||||
path="/movies/explore/:source/:category"
|
path="/movies/explore/:source/:category"
|
||||||
exact
|
exact
|
||||||
component={MovieList}
|
component={MovieList}
|
||||||
/>
|
/>
|
||||||
<ShowsRoute path="/shows/polochon" exact component={ShowList} />
|
<Route path="/shows/polochon" exact component={ShowList} />
|
||||||
<ShowsRoute path="/shows/wishlist" exact component={ShowList} />
|
<Route path="/shows/wishlist" exact component={ShowList} />
|
||||||
<ShowsRoute path="/shows/search/:search" exact component={ShowList} />
|
<Route path="/shows/search/:search" exact component={ShowList} />
|
||||||
<ShowsRoute
|
<Route
|
||||||
path="/shows/explore/:source/:category"
|
path="/shows/explore/:source/:category"
|
||||||
exact
|
exact
|
||||||
component={ShowList}
|
component={ShowList}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useCallback } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { OrderedMap, Map } from "immutable";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { connect } from "react-redux";
|
import { Map } from "immutable";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
selectMovie,
|
selectMovie,
|
||||||
updateFilter,
|
updateFilter,
|
||||||
@ -20,57 +21,86 @@ import { ShowMore } from "../buttons/showMore";
|
|||||||
import { MovieSubtitlesButton } from "./subtitlesButton";
|
import { MovieSubtitlesButton } from "./subtitlesButton";
|
||||||
import { MovieTorrentsButton } from "./torrentsButton";
|
import { MovieTorrentsButton } from "./torrentsButton";
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
const fetchUrl = (match) => {
|
||||||
return {
|
switch (match.path) {
|
||||||
loading: state.movieStore.get("loading"),
|
case "/movies/polochon":
|
||||||
movies: state.movieStore.get("movies"),
|
return "/movies/polochon";
|
||||||
filter: state.movieStore.get("filter"),
|
case "/movies/wishlist":
|
||||||
selectedImdbId: state.movieStore.get("selectedImdbId"),
|
return "/wishlist/movies";
|
||||||
exploreOptions: state.movieStore.get("exploreOptions"),
|
case "/movies/search/:search":
|
||||||
};
|
return "/movies/search/" + match.params.search;
|
||||||
}
|
case "/movies/explore/:source/:category":
|
||||||
const mapDispatchToProps = {
|
return (
|
||||||
selectMovie,
|
"/movies/explore?source=" +
|
||||||
updateFilter,
|
encodeURI(match.params.source) +
|
||||||
movieWishlistToggle,
|
"&category=" +
|
||||||
fetchMovies,
|
encodeURI(match.params.category)
|
||||||
getMovieExploreOptions,
|
);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const MovieList = (props) => {
|
const MovieList = ({ match }) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const url = fetchUrl(match);
|
||||||
|
if (url !== null) {
|
||||||
|
dispatch(fetchMovies(url));
|
||||||
|
}
|
||||||
|
}, [dispatch, match]);
|
||||||
|
|
||||||
|
const loading = useSelector((state) => state.movieStore.get("loading"));
|
||||||
|
const movies = useSelector((state) => state.movieStore.get("movies"));
|
||||||
|
const filter = useSelector((state) => state.movieStore.get("filter"));
|
||||||
|
const selectedImdbId = useSelector((state) =>
|
||||||
|
state.movieStore.get("selectedImdbId")
|
||||||
|
);
|
||||||
|
const exploreOptions = useSelector((state) =>
|
||||||
|
state.movieStore.get("exploreOptions")
|
||||||
|
);
|
||||||
|
|
||||||
let selectedMovie = Map();
|
let selectedMovie = Map();
|
||||||
if (props.movies !== undefined && props.movies.has(props.selectedImdbId)) {
|
if (movies !== undefined && movies.has(selectedImdbId)) {
|
||||||
selectedMovie = props.movies.get(props.selectedImdbId);
|
selectedMovie = movies.get(selectedImdbId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectFunc = useCallback((id) => dispatch(selectMovie(id)), [dispatch]);
|
||||||
|
const filterFunc = useCallback((filter) => dispatch(updateFilter(filter)), [
|
||||||
|
dispatch,
|
||||||
|
]);
|
||||||
|
const exploreFetchOptions = useCallback(
|
||||||
|
() => dispatch(getMovieExploreOptions()),
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<ListPosters
|
<ListPosters
|
||||||
data={props.movies}
|
data={movies}
|
||||||
type="movies"
|
type="movies"
|
||||||
placeHolder="Filter movies..."
|
placeHolder="Filter movies..."
|
||||||
exploreFetchOptions={props.getMovieExploreOptions}
|
exploreFetchOptions={exploreFetchOptions}
|
||||||
exploreOptions={props.exploreOptions}
|
exploreOptions={exploreOptions}
|
||||||
selectedImdbId={props.selectedImdbId}
|
selectedImdbId={selectedImdbId}
|
||||||
updateFilter={props.updateFilter}
|
updateFilter={filterFunc}
|
||||||
filter={props.filter}
|
filter={filter}
|
||||||
onClick={props.selectMovie}
|
onClick={selectFunc}
|
||||||
onDoubleClick={function () {
|
onDoubleClick={() => {}}
|
||||||
return;
|
onKeyEnter={() => {}}
|
||||||
}}
|
params={match.params}
|
||||||
onKeyEnter={function () {
|
loading={loading}
|
||||||
return;
|
|
||||||
}}
|
|
||||||
params={props.match.params}
|
|
||||||
loading={props.loading}
|
|
||||||
/>
|
/>
|
||||||
<ListDetails
|
<ListDetails
|
||||||
data={selectedMovie}
|
data={selectedMovie}
|
||||||
loading={props.loading}
|
loading={loading}
|
||||||
wishlist={() =>
|
wishlist={() =>
|
||||||
props.movieWishlistToggle(
|
dispatch(
|
||||||
selectedMovie.get("imdb_id"),
|
movieWishlistToggle(
|
||||||
isWishlisted(selectedMovie)
|
selectedMovie.get("imdb_id"),
|
||||||
|
isWishlisted(selectedMovie)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@ -96,11 +126,6 @@ const MovieList = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
MovieList.propTypes = {
|
MovieList.propTypes = {
|
||||||
movies: PropTypes.instanceOf(OrderedMap),
|
|
||||||
exploreOptions: PropTypes.instanceOf(Map),
|
|
||||||
selectedImdbId: PropTypes.string,
|
|
||||||
filter: PropTypes.string,
|
|
||||||
loading: PropTypes.bool,
|
|
||||||
fetchMovies: PropTypes.func,
|
fetchMovies: PropTypes.func,
|
||||||
getMovieExploreOptions: PropTypes.func,
|
getMovieExploreOptions: PropTypes.func,
|
||||||
updateFilter: PropTypes.func,
|
updateFilter: PropTypes.func,
|
||||||
@ -109,4 +134,4 @@ MovieList.propTypes = {
|
|||||||
match: PropTypes.object,
|
match: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(MovieList);
|
export default MovieList;
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { Route } from "react-router-dom";
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { fetchMovies } from "../../actions/movies";
|
|
||||||
|
|
||||||
const MoviesRoute = ({ component: Component, fetchMovies, ...otherProps }) => {
|
|
||||||
return (
|
|
||||||
<Route
|
|
||||||
{...otherProps}
|
|
||||||
render={(props) => {
|
|
||||||
let fetchUrl = "";
|
|
||||||
switch (props.match.path) {
|
|
||||||
case "/movies/polochon":
|
|
||||||
fetchUrl = "/movies/polochon";
|
|
||||||
break;
|
|
||||||
case "/movies/wishlist":
|
|
||||||
fetchUrl = "/wishlist/movies";
|
|
||||||
break;
|
|
||||||
case "/movies/search/:search":
|
|
||||||
fetchUrl = "/movies/search/" + props.match.params.search;
|
|
||||||
break;
|
|
||||||
case "/movies/explore/:source/:category":
|
|
||||||
fetchUrl =
|
|
||||||
"/movies/explore?source=" +
|
|
||||||
encodeURI(props.match.params.source) +
|
|
||||||
"&category=" +
|
|
||||||
encodeURI(props.match.params.category);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fetchUrl != "") {
|
|
||||||
fetchMovies(fetchUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Component {...props} />;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
MoviesRoute.propTypes = {
|
|
||||||
component: PropTypes.object,
|
|
||||||
match: PropTypes.object,
|
|
||||||
fetchMovies: PropTypes.func.isRequired,
|
|
||||||
getMovieExploreOptions: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(null, { fetchMovies })(MoviesRoute);
|
|
@ -1,11 +1,12 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useCallback } 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 { useSelector, useDispatch } from "react-redux";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
fetchShows,
|
||||||
selectShow,
|
selectShow,
|
||||||
showWishlistToggle,
|
showWishlistToggle,
|
||||||
getShowDetails,
|
|
||||||
updateFilter,
|
updateFilter,
|
||||||
getShowExploreOptions,
|
getShowExploreOptions,
|
||||||
} from "../../actions/shows";
|
} from "../../actions/shows";
|
||||||
@ -15,57 +16,90 @@ import { isWishlisted } from "../../utils";
|
|||||||
import ListDetails from "../list/details";
|
import ListDetails from "../list/details";
|
||||||
import ListPosters from "../list/posters";
|
import ListPosters from "../list/posters";
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
const fetchUrl = (match) => {
|
||||||
return {
|
switch (match.path) {
|
||||||
loading: state.showsStore.get("loading"),
|
case "/shows/polochon":
|
||||||
shows: state.showsStore.get("shows"),
|
return "/shows/polochon";
|
||||||
filter: state.showsStore.get("filter"),
|
case "/shows/wishlist":
|
||||||
selectedImdbId: state.showsStore.get("selectedImdbId"),
|
return "/wishlist/shows";
|
||||||
exploreOptions: state.showsStore.get("exploreOptions"),
|
case "/shows/search/:search":
|
||||||
};
|
return "/shows/search/" + match.params.search;
|
||||||
}
|
case "/shows/explore/:source/:category":
|
||||||
const mapDispatchToProps = {
|
return (
|
||||||
selectShow,
|
"/shows/explore?source=" +
|
||||||
showWishlistToggle,
|
encodeURI(match.params.source) +
|
||||||
getShowDetails,
|
"&category=" +
|
||||||
updateFilter,
|
encodeURI(match.params.category)
|
||||||
getShowExploreOptions,
|
);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const ShowList = (props) => {
|
const ShowList = ({ match, history }) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const url = fetchUrl(match);
|
||||||
|
if (url !== null) {
|
||||||
|
dispatch(fetchShows(url));
|
||||||
|
}
|
||||||
|
}, [dispatch, match]);
|
||||||
|
|
||||||
|
const loading = useSelector((state) => state.showsStore.get("loading"));
|
||||||
|
const shows = useSelector((state) => state.showsStore.get("shows"));
|
||||||
|
const filter = useSelector((state) => state.showsStore.get("filter"));
|
||||||
|
const selectedImdbId = useSelector((state) =>
|
||||||
|
state.showsStore.get("selectedImdbId")
|
||||||
|
);
|
||||||
|
const exploreOptions = useSelector((state) =>
|
||||||
|
state.showsStore.get("exploreOptions")
|
||||||
|
);
|
||||||
|
|
||||||
const showDetails = (imdbId) => {
|
const showDetails = (imdbId) => {
|
||||||
props.history.push("/shows/details/" + imdbId);
|
history.push("/shows/details/" + imdbId);
|
||||||
};
|
};
|
||||||
|
|
||||||
let selectedShow = Map();
|
let selectedShow = Map();
|
||||||
if (props.selectedImdbId !== "") {
|
if (selectedImdbId !== "") {
|
||||||
selectedShow = props.shows.get(props.selectedImdbId);
|
selectedShow = shows.get(selectedImdbId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectFunc = useCallback((id) => dispatch(selectShow(id)), [dispatch]);
|
||||||
|
const filterFunc = useCallback((filter) => dispatch(updateFilter(filter)), [
|
||||||
|
dispatch,
|
||||||
|
]);
|
||||||
|
const exploreFetchOptions = useCallback(
|
||||||
|
() => dispatch(getShowExploreOptions()),
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="row" id="container">
|
<div className="row" id="container">
|
||||||
<ListPosters
|
<ListPosters
|
||||||
data={props.shows}
|
data={shows}
|
||||||
type="shows"
|
type="shows"
|
||||||
placeHolder="Filter shows..."
|
placeHolder="Filter shows..."
|
||||||
exploreOptions={props.exploreOptions}
|
exploreOptions={exploreOptions}
|
||||||
exploreFetchOptions={props.getShowExploreOptions}
|
exploreFetchOptions={exploreFetchOptions}
|
||||||
updateFilter={props.updateFilter}
|
updateFilter={filterFunc}
|
||||||
selectedImdbId={props.selectedImdbId}
|
selectedImdbId={selectedImdbId}
|
||||||
filter={props.filter}
|
filter={filter}
|
||||||
onClick={props.selectShow}
|
onClick={selectFunc}
|
||||||
onDoubleClick={showDetails}
|
onDoubleClick={showDetails}
|
||||||
onKeyEnter={showDetails}
|
onKeyEnter={showDetails}
|
||||||
params={props.match.params}
|
params={match.params}
|
||||||
loading={props.loading}
|
loading={loading}
|
||||||
/>
|
/>
|
||||||
<ListDetails
|
<ListDetails
|
||||||
data={selectedShow}
|
data={selectedShow}
|
||||||
loading={props.loading}
|
loading={loading}
|
||||||
wishlist={() =>
|
wishlist={() =>
|
||||||
props.showWishlistToggle(
|
dispatch(
|
||||||
isWishlisted(selectedShow),
|
showWishlistToggle(
|
||||||
selectedShow.get("imdb_id")
|
isWishlisted(selectedShow),
|
||||||
|
selectedShow.get("imdb_id")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@ -85,15 +119,5 @@ const ShowList = (props) => {
|
|||||||
ShowList.propTypes = {
|
ShowList.propTypes = {
|
||||||
match: PropTypes.object,
|
match: PropTypes.object,
|
||||||
history: PropTypes.object,
|
history: PropTypes.object,
|
||||||
shows: PropTypes.instanceOf(Map),
|
|
||||||
exploreOptions: PropTypes.instanceOf(Map),
|
|
||||||
selectedImdbId: PropTypes.string,
|
|
||||||
filter: PropTypes.string,
|
|
||||||
loading: PropTypes.bool,
|
|
||||||
showWishlistToggle: PropTypes.func,
|
|
||||||
selectShow: PropTypes.func,
|
|
||||||
getShowDetails: PropTypes.func,
|
|
||||||
updateFilter: PropTypes.func,
|
|
||||||
getShowExploreOptions: PropTypes.func,
|
|
||||||
};
|
};
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(ShowList);
|
export default ShowList;
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { Route } from "react-router-dom";
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { fetchShows } from "../../actions/shows";
|
|
||||||
|
|
||||||
const ShowsRoute = ({ component: Component, fetchShows, ...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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fetchUrl != "") {
|
|
||||||
fetchShows(fetchUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Component {...props} />;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
ShowsRoute.propTypes = {
|
|
||||||
component: PropTypes.object,
|
|
||||||
match: PropTypes.object,
|
|
||||||
fetchShows: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(null, {
|
|
||||||
fetchShows,
|
|
||||||
})(ShowsRoute);
|
|
Loading…
x
Reference in New Issue
Block a user