import React, { Component } from 'react'; import formatBytes from './format-bytes' import {ListItem} from 'material-ui/List'; import Divider from 'material-ui/Divider'; import Spinner24 from './images/spinner_24.gif' import LinearProgress from 'material-ui/LinearProgress'; const contentIcon = (type, category) => { if(category == 'xxx') { return ( ) } switch(type) { case 'video': return ( ) case 'audio': return ( ) case 'pictures': return ( ) case 'application': return ( ) case 'books': return ( ) case 'archive': return ( ) case 'disc': return ( ) default: return ( ) } }; export {contentIcon} export default class Torrent extends Component { state = { downloading: false, askDownloading: false, downloadProgress: {} } componentDidMount() { this.downloading = (hash) => { if(this.props.torrent.hash != hash) return; this.setState({downloading: true}) } window.torrentSocket.on('downloading', this.downloading); this.downloadDone = (hash, canceled) => { if(this.props.torrent.hash != hash) return; this.setState({ downloading: false, askDownloading: !canceled }) } window.torrentSocket.on('downloadDone', this.downloadDone); this.downloadProgress = (hash, progress) => { if(this.props.torrent.hash != hash) return; this.setState({ downloading: true, askDownloading: true, downloadProgress: progress }) } window.torrentSocket.on('downloadProgress', this.downloadProgress); } componentWillUnmount() { if(this.downloading) window.torrentSocket.off('downloading', this.downloading); if(this.downloadDone) window.torrentSocket.off('downloadDone', this.downloadDone); if(this.downloadProgress) window.torrentSocket.off('downloadProgress', this.downloadProgress); } render() { const torrent = this.props.torrent; return (
{ const link = '/torrent/' + torrent.hash; if(e.button === 1) return false; if(e.ctrlKey && e.button === 0) { let win = window.open(link, '_blank'); //win.focus(); return true; } window.router(link) }} primaryText={ { if(node) node.onclick = () => { return false } }}> {torrent.name} } secondaryText={ { if(node) node.onclick = () => { return false } }}>
{ formatBytes(torrent.size, 1) + ' (' + torrent.files + ' files)' }
{ this.state.downloading && }
{ torrent.path && torrent.path.length > 0 ? torrent.path.map((path, index) => { return
{path}
}) : null } { torrent.seeders || torrent.leechers || torrent.completed ?
0 ? '#00C853' : 'grey')}}>{torrent.seeders} seeders 0 ? '#AA00FF' : 'grey'), marginLeft: '12px'}}>{torrent.leechers} leechers 0 ? '#FF6D00' : 'grey'), marginLeft: '12px'}}>{torrent.completed} completed
: null }
} leftIcon={contentIcon(torrent.contentType, torrent.contentCategory)} rightIcon={
{ !this.state.askDownloading && !this.state.downloading ? { e.preventDefault(); e.stopPropagation(); this.setState({askDownloading: true}) window.torrentSocket.emit('download', `magnet:?xt=urn:btih:${torrent.hash}`) }} viewBox="0 0 56 56"> : this.state.askDownloading && !this.state.downloading ? : this.state.askDownloading && this.state.downloading && { e.preventDefault(); e.stopPropagation(); window.torrentSocket.emit('downloadCancel', torrent.hash) }} viewBox="0 0 18 18"> } { e.preventDefault(); e.stopPropagation(); var win = window.open(`magnet:?xt=urn:btih:${torrent.hash}`, '_self'); }} viewBox="0 0 24 24">
} />
) } }