Add button to add torrent in polochon

This commit is contained in:
Grégoire Delattre 2017-01-18 21:17:30 +01:00
parent b9b1fb356f
commit 8c16d8c78b
4 changed files with 56 additions and 24 deletions

View File

@ -87,7 +87,7 @@ func main() {
env.Handle("/shows/refresh", extmedias.RefreshShows).WithRole(users.UserRole).Methods("POST") env.Handle("/shows/refresh", extmedias.RefreshShows).WithRole(users.UserRole).Methods("POST")
env.Handle("/shows/explore", extmedias.ExploreShows).WithRole(users.UserRole).Methods("GET") env.Handle("/shows/explore", extmedias.ExploreShows).WithRole(users.UserRole).Methods("GET")
env.Handle("/shows/search", shows.SearchShow).WithRole(users.UserRole).Methods("POST") env.Handle("/shows/search", shows.SearchShow).WithRole(users.UserRole).Methods("POST")
env.Handle("/download", torrents.DownloadHandler).WithRole(users.UserRole).Methods("POST") env.Handle("/torrents", torrents.DownloadHandler).WithRole(users.UserRole).Methods("POST")
n := negroni.Classic() n := negroni.Classic()
n.Use(authMiddleware) n.Use(authMiddleware)

View File

@ -142,3 +142,17 @@ export function selectShow(imdbId) {
imdbId imdbId
} }
} }
// ======================
// AddTorrent
// ======================
export function addTorrent(url) {
return request(
'ADD_TORRENT',
configureAxios().post('/torrents', {
url: url,
}),
"Torrent added",
)
}

View File

@ -40,7 +40,10 @@ class MovieButtons extends React.Component {
} }
{this.props.movie.torrents && {this.props.movie.torrents &&
<TorrentsButton torrents={this.props.movie.torrents} /> <TorrentsButton
torrents={this.props.movie.torrents}
addTorrent={this.props.addTorrent}
/>
} }
<a type="button" className="btn btn-warning btn-sm" href={imdb_link}> <a type="button" className="btn btn-warning btn-sm" href={imdb_link}>
@ -104,6 +107,7 @@ export default class MovieList extends React.Component {
movie={selectedMovie} movie={selectedMovie}
fetching={this.props.movieStore.fetchingDetails} fetching={this.props.movieStore.fetchingDetails}
getMovieDetails={this.props.getMovieDetails} getMovieDetails={this.props.getMovieDetails}
addTorrent={this.props.addTorrent}
/> />
</ListDetails> </ListDetails>
} }

View File

@ -2,15 +2,26 @@ import React from 'react'
import { DropdownButton, MenuItem } from 'react-bootstrap' import { DropdownButton, MenuItem } from 'react-bootstrap'
export default function TorrentsButton(props) { export default class TorrentsButton extends React.Component {
const entries = buildMenuItems(props.torrents); constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e, url) {
e.preventDefault();
this.props.addTorrent(url);
}
render() {
const entries = buildMenuItems(this.props.torrents);
return ( return (
<DropdownButton className="btn btn-default btn-sm" title="Torrents" dropup id="download-torrents-button"> <DropdownButton className="btn btn-default btn-sm" title="Torrents" id="download-torrents-button" dropup>
{entries.map(function(e, index) { {entries.map(function(e, index) {
switch (e.type) { switch (e.type) {
case 'header': case 'header':
return ( return (
<MenuItem key={index} className="text-warning" header>{e.value}</MenuItem> <MenuItem key={index} className="text-warning" header>
{e.value}
</MenuItem>
); );
case 'divider': case 'divider':
return ( return (
@ -18,13 +29,16 @@ export default function TorrentsButton(props) {
); );
case 'entry': case 'entry':
return ( return (
<MenuItem key={index}>{e.quality}</MenuItem> <MenuItem key={index} href={e.url} onClick={(event) => this.handleClick(event, e.url)}>
{e.quality}
</MenuItem>
); );
} }
})} }, this)}
</DropdownButton> </DropdownButton>
); );
} }
}
function buildMenuItems(torrents) { function buildMenuItems(torrents) {
// Organise by source // Organise by source