import React, { Component } from 'react'; import formatBytes from './format-bytes' import {ListItem} from 'material-ui/List'; import Divider from 'material-ui/Divider'; import PagesPie from './pages-pie.js'; import TorrentPage from './torrent-page' import Spinner24 from './images/spinner_24.gif' import LinearProgress from 'material-ui/LinearProgress'; const contentIcon = (type, category, fill = 'grey') => { 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: {} } constructor(props) { super(props) if(props.download) { const { progress, downloaded, speed } = props.download this.state.downloadProgress = { progress, downloaded, speed } } } 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 (