Grégoire Delattre c1bd0bd3bc Update routes and auth
* Use the onEnter hook of the router to fetch data
* Remove the plugin to check if the user is authenticated, this is now
done by the onEnter function of the router
* Update the backend to search using GET queries
* Cleanup the (now useless) code in the components to fetch the datas
2017-05-19 23:06:20 +02:00

96 lines
3.1 KiB
JavaScript

import React from 'react'
import DownloadButton from '../buttons/download'
import TorrentsButton from './torrents'
import ActionsButton from './actions'
import ListPosters from '../list/posters'
import ListDetails from '../list/details'
function MovieButtons(props) {
const imdb_link = `http://www.imdb.com/title/${props.movie.imdb_id}`;
const hasMovie = (props.movie.polochon_url !== "");
return (
<div className="list-details-buttons btn-toolbar">
<ActionsButton
fetching={props.fetching}
movieId={props.movie.imdb_id}
getDetails={props.getMovieDetails}
deleteMovie={props.deleteMovie}
isUserAdmin={props.isUserAdmin}
hasMovie={hasMovie}
wishlisted={props.movie.wishlisted}
addToWishlist={props.addToWishlist}
deleteFromWishlist={props.deleteFromWishlist}
lastFetchUrl={props.lastFetchUrl}
fetchMovies={props.fetchMovies}
/>
{props.movie.torrents &&
<TorrentsButton
torrents={props.movie.torrents}
addTorrent={props.addTorrent}
/>
}
<DownloadButton url={props.movie.polochon_url}/>
<a type="button" className="btn btn-warning btn-sm" href={imdb_link}>
<i className="fa fa-external-link"></i> IMDB
</a>
</div>
);
}
export default class MovieList extends React.Component {
constructor(props) {
super(props);
}
render() {
const movies = this.props.movieStore.movies;
const selectedMovieId = this.props.movieStore.selectedImdbId;
let index = movies.map((el) => el.imdb_id).indexOf(selectedMovieId);
if (index === -1) {
index = 0;
}
const selectedMovie = movies[index];
return (
<div className="row" id="container">
<ListPosters
data={movies}
type="movies"
formModel="movieStore"
filterControlModel="movieStore.filter"
filterControlPlaceHolder="Filter movies..."
fetchExploreOptions={this.props.getMovieExploreOptions}
exploreOptions={this.props.movieStore.exploreOptions}
explore={this.props.exploreMovies}
selectedImdbId={selectedMovieId}
filter={this.props.movieStore.filter}
perPage={this.props.movieStore.perPage}
onClick={this.props.selectMovie}
params={this.props.params}
router={this.props.router}
loading={this.props.movieStore.loading}
/>
{selectedMovie &&
<ListDetails data={selectedMovie}>
<MovieButtons
movie={selectedMovie}
fetching={this.props.movieStore.fetchingDetails}
getMovieDetails={this.props.getMovieDetails}
addTorrent={this.props.addTorrent}
deleteMovie={this.props.deleteMovie}
isUserAdmin={this.props.userStore.isAdmin}
addToWishlist={this.props.addMovieToWishlist}
deleteFromWishlist={this.props.deleteMovieFromWishlist}
fetchMovies={this.props.fetchMovies}
lastFetchUrl={this.props.lastFetchUrl}
/>
</ListDetails>
}
</div>
);
}
}