2016-05-14 14:26:54 +02:00
|
|
|
var removeIconColumnStyle = {
|
|
|
|
fontSize: '1.3em',
|
|
|
|
height: '120px',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
progressBarStyle = {
|
|
|
|
height: '15px',
|
|
|
|
width: '230px',
|
|
|
|
backgroundColor: '#444',
|
|
|
|
border: '2px solid #eee',
|
|
|
|
display: 'inline-block',
|
2016-05-16 10:19:41 +02:00
|
|
|
},
|
|
|
|
myFilesRowImgStyle = {
|
2016-05-20 12:12:42 +02:00
|
|
|
maxHeight: '100px',
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
float: 'left'
|
2016-05-10 12:36:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var MyFilesRow = React.createClass({
|
2016-05-14 14:26:54 +02:00
|
|
|
onRemoveClicked: function() {
|
|
|
|
var alertText = 'Are you sure you\'d like to remove "' + this.props.title + '?" This will ' +
|
|
|
|
(this.completed ? ' stop the download and ' : '') +
|
|
|
|
'permanently remove the file from your system.';
|
|
|
|
|
|
|
|
if (confirm(alertText)) {
|
|
|
|
lbry.deleteFile(this.props.lbryUri);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onPauseResumeClicked: function() {
|
|
|
|
if (this.props.stopped) {
|
|
|
|
lbry.startFile(this.props.lbryUri);
|
|
|
|
} else {
|
|
|
|
lbry.stopFile(this.props.lbryUri);
|
|
|
|
}
|
|
|
|
},
|
2016-05-10 12:36:54 +02:00
|
|
|
render: function() {
|
2016-05-14 14:26:54 +02:00
|
|
|
if (this.props.completed) {
|
|
|
|
var pauseLink = null;
|
|
|
|
var curProgressBarStyle = {display: 'none'};
|
|
|
|
} else {
|
|
|
|
var pauseLink = <Link icon={this.props.stopped ? 'icon-play' : 'icon-pause'}
|
|
|
|
label={this.props.stopped ? 'Resume download' : 'Pause download'}
|
|
|
|
onClick={() => { this.onPauseResumeClicked() }} />;
|
|
|
|
|
|
|
|
var curProgressBarStyle = Object.assign({}, progressBarStyle);
|
|
|
|
curProgressBarStyle.width = this.props.ratioLoaded * 230;
|
|
|
|
curProgressBarStyle.borderRightWidth = 230 - (this.props.ratioLoaded * 230) + 2;
|
|
|
|
}
|
2016-05-16 10:19:41 +02:00
|
|
|
|
|
|
|
if (this.props.showWatchButton) {
|
2016-05-20 12:39:02 +02:00
|
|
|
var watchButton = <WatchLink streamName={this.props.lbryUri} button='primary' />
|
2016-05-16 10:19:41 +02:00
|
|
|
} else {
|
2016-05-20 12:39:02 +02:00
|
|
|
var watchButton = null;
|
2016-05-16 10:19:41 +02:00
|
|
|
}
|
|
|
|
|
2016-05-10 12:36:54 +02:00
|
|
|
return (
|
2016-05-14 14:26:54 +02:00
|
|
|
<div className="row-fluid">
|
|
|
|
<div className="span3">
|
2016-05-16 10:19:41 +02:00
|
|
|
<img src={this.props.imgUrl} alt={'Photo for ' + this.props.title} style={myFilesRowImgStyle} />
|
2016-05-14 14:26:54 +02:00
|
|
|
</div>
|
|
|
|
<div className="span6">
|
|
|
|
<h2>{this.props.title}</h2>
|
|
|
|
<div className={this.props.completed ? 'hidden' : ''} style={curProgressBarStyle}></div>
|
|
|
|
{ ' ' }
|
|
|
|
{this.props.completed ? 'Download complete' : (parseInt(this.props.ratioLoaded * 100) + '%')}
|
|
|
|
<div>{ pauseLink }</div>
|
2016-05-20 12:39:02 +02:00
|
|
|
<div>{ watchButton }</div>
|
2016-05-14 14:26:54 +02:00
|
|
|
</div>
|
|
|
|
<div className="span1" style={removeIconColumnStyle}>
|
2016-05-16 07:48:27 +02:00
|
|
|
<Link icon="icon-close" title="Remove file" onClick={() => { this.onRemoveClicked() } } /><br />
|
2016-05-14 14:26:54 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-05-10 12:36:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var MyFilesPage = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
filesInfo: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
componentWillMount: function() {
|
2016-05-14 14:26:54 +02:00
|
|
|
this.updateFilesInfo();
|
|
|
|
},
|
|
|
|
updateFilesInfo: function() {
|
2016-05-10 12:36:54 +02:00
|
|
|
lbry.getFilesInfo((filesInfo) => {
|
|
|
|
this.setState({
|
2016-05-14 14:26:54 +02:00
|
|
|
filesInfo: (filesInfo ? filesInfo : []),
|
2016-05-10 12:36:54 +02:00
|
|
|
});
|
2016-05-14 14:26:54 +02:00
|
|
|
setTimeout(() => { this.updateFilesInfo() }, 1000);
|
2016-05-10 12:36:54 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
render: function() {
|
2016-05-14 14:26:54 +02:00
|
|
|
if (this.state.filesInfo === null) {
|
2016-05-10 12:36:54 +02:00
|
|
|
return null;
|
2016-05-16 10:19:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.state.filesInfo.length) {
|
|
|
|
var content = <span>You haven't downloaded anything from LBRY yet. Go <Link href="/" label="search for your first download" />!</span>;
|
2016-05-10 12:36:54 +02:00
|
|
|
} else {
|
2016-05-16 10:19:41 +02:00
|
|
|
var content = [];
|
|
|
|
for (let fileInfo of this.state.filesInfo) {
|
|
|
|
let {completed, written_bytes, total_bytes, lbry_uri, file_name, stopped, metadata} = fileInfo;
|
|
|
|
let {name, stream_name, thumbnail} = metadata;
|
|
|
|
|
|
|
|
var title = (name || stream_name || ('lbry://' + lbry_uri));
|
|
|
|
var ratioLoaded = written_bytes / total_bytes;
|
|
|
|
var showWatchButton = (lbry.getMediaType(file_name) == 'video');
|
|
|
|
|
|
|
|
content.push(<MyFilesRow lbryUri={lbry_uri} title={title} completed={completed} stopped={stopped}
|
|
|
|
ratioLoaded={ratioLoaded} imgUrl={thumbnail}
|
|
|
|
showWatchButton={showWatchButton}/>);
|
2016-05-10 12:36:54 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 10:19:41 +02:00
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<h1>My files</h1>
|
2016-05-20 12:41:04 +02:00
|
|
|
<section>
|
2016-05-16 10:19:41 +02:00
|
|
|
{content}
|
2016-05-20 12:41:04 +02:00
|
|
|
</section>
|
2016-05-16 10:19:41 +02:00
|
|
|
<section>
|
|
|
|
<Link href="/" label="<< Return" />
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
);
|
2016-05-10 12:36:54 +02:00
|
|
|
}
|
|
|
|
});
|