2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
|
|
|
import {Link, WatchLink} from '../component/link.js';
|
2016-12-07 22:24:33 +01:00
|
|
|
import {Menu, MenuItem} from '../component/menu.js';
|
2016-11-22 21:19:08 +01:00
|
|
|
import Modal from '../component/modal.js';
|
|
|
|
import {BusyMessage, Thumbnail} from '../component/common.js';
|
|
|
|
|
2016-05-30 14:54:08 +02:00
|
|
|
var moreMenuStyle = {
|
2016-05-29 13:04:25 +02:00
|
|
|
position: 'absolute',
|
|
|
|
display: 'block',
|
|
|
|
top: '26px',
|
2016-10-02 09:33:32 +02:00
|
|
|
right: '13px',
|
2016-05-29 13:04:25 +02:00
|
|
|
};
|
|
|
|
var MyFilesRowMoreMenu = React.createClass({
|
2016-10-21 09:56:37 +02:00
|
|
|
propTypes: {
|
|
|
|
title: React.PropTypes.string.isRequired,
|
|
|
|
path: React.PropTypes.string.isRequired,
|
|
|
|
completed: React.PropTypes.bool.isRequired,
|
|
|
|
lbryUri: React.PropTypes.string.isRequired,
|
|
|
|
},
|
|
|
|
handleRevealClicked: function() {
|
2016-05-30 14:54:08 +02:00
|
|
|
lbry.revealFile(this.props.path);
|
|
|
|
},
|
2016-10-21 09:56:37 +02:00
|
|
|
handleRemoveClicked: function() {
|
2016-05-30 14:54:08 +02:00
|
|
|
lbry.deleteFile(this.props.lbryUri, false);
|
|
|
|
},
|
2016-10-21 09:56:37 +02:00
|
|
|
handleDeleteClicked: function() {
|
|
|
|
this.setState({
|
|
|
|
modal: 'confirmDelete',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleDeleteConfirmed: function() {
|
|
|
|
lbry.deleteFile(this.props.lbryUri);
|
2016-11-18 05:32:24 +01:00
|
|
|
this.setState({
|
2016-10-21 09:56:37 +02:00
|
|
|
modal: null,
|
|
|
|
});
|
|
|
|
},
|
2016-11-18 05:36:14 +01:00
|
|
|
closeModal: function() {
|
|
|
|
this.setState({
|
2016-10-21 09:56:37 +02:00
|
|
|
modal: null,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
modal: null,
|
|
|
|
};
|
2016-05-29 13:04:25 +02:00
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
2016-05-30 14:54:08 +02:00
|
|
|
<div style={moreMenuStyle}>
|
2016-05-29 13:04:25 +02:00
|
|
|
<Menu {...this.props}>
|
2016-08-08 05:31:21 +02:00
|
|
|
<section className="card">
|
2016-10-21 09:56:37 +02:00
|
|
|
<MenuItem onClick={this.handleRevealClicked} label="Reveal file" /> {/* @TODO: Switch to OS specific wording */}
|
|
|
|
<MenuItem onClick={this.handleRemoveClicked} label="Remove from LBRY" />
|
|
|
|
<MenuItem onClick={this.handleDeleteClicked} label="Remove and delete file" />
|
2016-08-08 05:31:21 +02:00
|
|
|
</section>
|
2016-05-29 13:04:25 +02:00
|
|
|
</Menu>
|
2016-11-18 05:36:14 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'confirmDelete'} type="confirm" confirmButtonLabel="Delete File"
|
|
|
|
onConfirmed={this.handleDeleteConfirmed} onAborted={this.closeModal}>
|
2016-10-21 09:56:37 +02:00
|
|
|
Are you sure you'd like to delete <cite>{this.props.title}</cite>? This will {this.props.completed ? ' stop the download and ' : ''}
|
|
|
|
permanently remove the file from your system.
|
|
|
|
</Modal>
|
2016-05-29 13:04:25 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var moreButtonColumnStyle = {
|
2016-08-07 17:27:00 +02:00
|
|
|
height: '120px',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
moreButtonContainerStyle = {
|
|
|
|
display: 'block',
|
|
|
|
position: 'relative',
|
|
|
|
},
|
|
|
|
moreButtonStyle = {
|
|
|
|
fontSize: '1.3em',
|
|
|
|
},
|
|
|
|
progressBarStyle = {
|
|
|
|
height: '15px',
|
|
|
|
width: '230px',
|
|
|
|
backgroundColor: '#444',
|
|
|
|
border: '2px solid #eee',
|
|
|
|
display: 'inline-block',
|
2016-08-27 08:18:19 +02:00
|
|
|
},
|
2016-08-07 17:27:00 +02:00
|
|
|
artStyle = {
|
|
|
|
maxHeight: '100px',
|
2016-08-26 12:54:30 +02:00
|
|
|
maxWidth: '100%',
|
2016-08-07 17:27:00 +02:00
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
};
|
2016-05-10 12:36:54 +02:00
|
|
|
var MyFilesRow = React.createClass({
|
2016-05-14 14:26:54 +02:00
|
|
|
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-30 14:54:08 +02:00
|
|
|
//@TODO: Convert progress bar to reusable component
|
|
|
|
|
|
|
|
var progressBarWidth = 230;
|
2016-05-20 12:42:32 +02:00
|
|
|
|
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);
|
2016-05-20 12:42:32 +02:00
|
|
|
curProgressBarStyle.width = Math.floor(this.props.ratioLoaded * progressBarWidth) + 'px';
|
|
|
|
curProgressBarStyle.borderRightWidth = progressBarWidth - Math.ceil(this.props.ratioLoaded * progressBarWidth) + 2;
|
2016-05-14 14:26:54 +02:00
|
|
|
}
|
2016-05-16 10:19:41 +02:00
|
|
|
|
|
|
|
if (this.props.showWatchButton) {
|
2016-05-20 12:42:32 +02:00
|
|
|
var watchButton = <WatchLink streamName={this.props.lbryUri} />
|
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-08-08 05:31:21 +02:00
|
|
|
<section className="card">
|
|
|
|
<div className="row-fluid">
|
|
|
|
<div className="span3">
|
2016-11-11 13:57:01 +01:00
|
|
|
<Thumbnail src={this.props.imgUrl} alt={'Photo for ' + this.props.title} style={artStyle} />
|
2016-08-08 05:31:21 +02:00
|
|
|
</div>
|
|
|
|
<div className="span8">
|
|
|
|
<h3>{this.props.pending ? this.props.title : <a href={'/?show=' + this.props.lbryUri}>{this.props.title}</a>}</h3>
|
|
|
|
{this.props.pending ? <em>This file is pending confirmation</em>
|
|
|
|
: (
|
|
|
|
<div>
|
|
|
|
<div className={this.props.completed ? 'hidden' : ''} style={curProgressBarStyle}></div>
|
|
|
|
{ ' ' }
|
2016-09-24 10:21:07 +02:00
|
|
|
{this.props.completed
|
|
|
|
? (this.props.isMine
|
|
|
|
? 'Published'
|
|
|
|
: 'Download complete')
|
|
|
|
: (parseInt(this.props.ratioLoaded * 100) + '%')}
|
2016-08-08 05:31:21 +02:00
|
|
|
<div>{ pauseLink }</div>
|
|
|
|
<div>{ watchButton }</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div className="span1" style={moreButtonColumnStyle}>
|
|
|
|
{this.props.pending ? null :
|
|
|
|
<div style={moreButtonContainerStyle}>
|
|
|
|
<Link style={moreButtonStyle} ref="moreButton" icon="icon-ellipsis-h" title="More Options" />
|
|
|
|
<MyFilesRowMoreMenu toggleButton={this.refs.moreButton} title={this.props.title}
|
2016-10-21 09:56:37 +02:00
|
|
|
completed={this.props.completed} lbryUri={this.props.lbryUri}
|
|
|
|
fileName={this.props.fileName} path={this.props.path}/>
|
2016-08-07 17:27:00 +02:00
|
|
|
</div>
|
2016-08-08 05:31:21 +02:00
|
|
|
}
|
|
|
|
</div>
|
2016-05-14 14:26:54 +02:00
|
|
|
</div>
|
2016-08-08 05:31:21 +02:00
|
|
|
</section>
|
2016-05-10 12:36:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var MyFilesPage = React.createClass({
|
2016-09-16 18:46:15 +02:00
|
|
|
_fileTimeout: null,
|
2016-12-13 19:11:01 +01:00
|
|
|
_fileInfoCheckRate: 300,
|
2016-09-16 18:46:15 +02:00
|
|
|
_fileInfoCheckNum: 0,
|
2016-11-18 11:54:57 +01:00
|
|
|
_sortFunctions: {
|
|
|
|
date: function(filesInfo) {
|
|
|
|
return filesInfo.reverse();
|
|
|
|
},
|
|
|
|
title: function(filesInfo) {
|
|
|
|
return filesInfo.sort(function(a, b) {
|
|
|
|
return ((a.metadata ? a.metadata.title.toLowerCase() : a.name) >
|
|
|
|
(b.metadata ? b.metadata.title.toLowerCase() : b.name));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
filename: function(filesInfo) {
|
|
|
|
return filesInfo.sort(function(a, b) {
|
|
|
|
return (a.file_name.toLowerCase() >
|
|
|
|
b.file_name.toLowerCase());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2016-09-16 18:46:15 +02:00
|
|
|
|
2016-05-10 12:36:54 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
filesInfo: null,
|
2016-11-09 13:00:25 +01:00
|
|
|
publishedFilesSdHashes: null,
|
2016-09-16 18:46:15 +02:00
|
|
|
filesAvailable: {},
|
2016-05-10 12:36:54 +02:00
|
|
|
};
|
|
|
|
},
|
2016-09-23 11:56:01 +02:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
show: null,
|
|
|
|
};
|
|
|
|
},
|
2016-08-08 00:13:17 +02:00
|
|
|
componentDidMount: function() {
|
|
|
|
document.title = "My Files";
|
|
|
|
},
|
2016-05-10 12:36:54 +02:00
|
|
|
componentWillMount: function() {
|
2016-11-09 13:00:25 +01:00
|
|
|
if (this.props.show == 'downloaded') {
|
|
|
|
this.getPublishedFilesSdHashes(() => {
|
|
|
|
this.updateFilesInfo();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.updateFilesInfo();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getPublishedFilesSdHashes: function(callback) {
|
|
|
|
// Determines which files were published by the user and saves their SD hashes in
|
|
|
|
// this.state.publishedFilesSdHashes. Used on the Downloads page to filter out claims published
|
|
|
|
// by the user.
|
|
|
|
var publishedFilesSdHashes = [];
|
|
|
|
lbry.getMyClaims((claimsInfo) => {
|
|
|
|
for (let claimInfo of claimsInfo) {
|
|
|
|
let metadata = JSON.parse(claimInfo.value);
|
|
|
|
publishedFilesSdHashes.push(metadata.sources.lbry_sd_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
publishedFilesSdHashes: publishedFilesSdHashes,
|
|
|
|
});
|
|
|
|
callback();
|
|
|
|
});
|
2016-05-14 14:26:54 +02:00
|
|
|
},
|
2016-08-08 02:57:12 +02:00
|
|
|
componentWillUnmount: function() {
|
2016-09-16 18:46:15 +02:00
|
|
|
if (this._fileTimeout)
|
2016-08-08 02:57:12 +02:00
|
|
|
{
|
2016-09-16 18:46:15 +02:00
|
|
|
clearTimeout(this._fileTimeout);
|
2016-08-08 02:57:12 +02:00
|
|
|
}
|
|
|
|
},
|
2016-05-14 14:26:54 +02:00
|
|
|
updateFilesInfo: function() {
|
2016-11-09 13:00:25 +01:00
|
|
|
this._fileInfoCheckNum += 1;
|
2016-09-16 18:46:15 +02:00
|
|
|
|
2016-11-09 13:00:25 +01:00
|
|
|
if (this.props.show == 'published') {
|
|
|
|
// We're in the Published tab, so populate this.state.filesInfo with data from the user's claims
|
|
|
|
lbry.getMyClaims((claimsInfo) => {
|
|
|
|
let newFilesInfo = [];
|
|
|
|
let claimInfoProcessedCount = 0;
|
|
|
|
for (let claimInfo of claimsInfo) {
|
|
|
|
let metadata = JSON.parse(claimInfo.value);
|
|
|
|
lbry.getFileInfoBySdHash(metadata.sources.lbry_sd_hash, (fileInfo) => {
|
|
|
|
claimInfoProcessedCount++;
|
|
|
|
if (fileInfo !== false) {
|
|
|
|
newFilesInfo.push(fileInfo);
|
|
|
|
}
|
|
|
|
if (claimInfoProcessedCount >= claimsInfo.length) {
|
2016-09-16 18:46:15 +02:00
|
|
|
this.setState({
|
2016-11-09 13:00:25 +01:00
|
|
|
filesInfo: newFilesInfo
|
2016-09-16 18:46:15 +02:00
|
|
|
});
|
2016-11-09 13:00:25 +01:00
|
|
|
|
|
|
|
this._fileTimeout = setTimeout(() => { this.updateFilesInfo() }, 1000);
|
2016-09-16 18:46:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-11-09 13:00:25 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// We're in the Downloaded tab, so populate this.state.filesInfo with files the user has in
|
|
|
|
// lbrynet, with published files filtered out.
|
|
|
|
lbry.getFilesInfo((filesInfo) => {
|
|
|
|
this.setState({
|
|
|
|
filesInfo: filesInfo.filter(({sd_hash}) => {
|
|
|
|
return this.state.publishedFilesSdHashes.indexOf(sd_hash) == -1;
|
|
|
|
}),
|
|
|
|
});
|
2016-09-16 18:46:15 +02:00
|
|
|
|
2016-11-09 13:00:25 +01:00
|
|
|
let newFilesAvailable;
|
|
|
|
if (!(this._fileInfoCheckNum % this._fileInfoCheckRate)) {
|
|
|
|
// Time to update file availability status
|
2016-09-16 18:46:15 +02:00
|
|
|
|
2016-11-09 13:00:25 +01:00
|
|
|
newFilesAvailable = {};
|
|
|
|
let filePeersCheckCount = 0;
|
|
|
|
for (let {sd_hash} of filesInfo) {
|
|
|
|
lbry.getPeersForBlobHash(sd_hash, (peers) => {
|
|
|
|
filePeersCheckCount++;
|
|
|
|
newFilesAvailable[sd_hash] = peers.length >= 0;
|
|
|
|
if (filePeersCheckCount >= filesInfo.length) {
|
|
|
|
this.setState({
|
|
|
|
filesAvailable: newFilesAvailable,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 18:46:15 +02:00
|
|
|
|
2016-11-09 13:00:25 +01:00
|
|
|
this._fileTimeout = setTimeout(() => { this.updateFilesInfo() }, 1000);
|
|
|
|
})
|
|
|
|
}
|
2016-05-10 12:36:54 +02:00
|
|
|
},
|
|
|
|
render: function() {
|
2016-11-09 13:00:25 +01:00
|
|
|
if (this.state.filesInfo === null || (this.props.show == 'downloaded' && this.state.publishedFileSdHashes === null)) {
|
2016-08-20 03:48:08 +02:00
|
|
|
return (
|
|
|
|
<main className="page">
|
2016-08-21 16:55:32 +02:00
|
|
|
<BusyMessage message="Loading" />
|
2016-08-20 03:48:08 +02:00
|
|
|
</main>
|
|
|
|
);
|
2016-11-09 12:58:58 +01:00
|
|
|
} else if (!this.state.filesInfo.length) {
|
|
|
|
return (
|
|
|
|
<main className="page">
|
|
|
|
{this.props.show == 'downloaded'
|
|
|
|
? <span>You haven't downloaded anything from LBRY yet. Go <Link href="/" label="search for your first download" />!</span>
|
|
|
|
: <span>You haven't published anything to LBRY yet.</span>}
|
|
|
|
</main>
|
|
|
|
);
|
2016-05-10 12:36:54 +02:00
|
|
|
} else {
|
2016-08-07 17:27:00 +02:00
|
|
|
var content = [],
|
2016-08-07 17:29:08 +02:00
|
|
|
seenUris = {};
|
|
|
|
|
2016-05-16 10:19:41 +02:00
|
|
|
for (let fileInfo of this.state.filesInfo) {
|
2016-05-30 14:54:08 +02:00
|
|
|
let {completed, written_bytes, total_bytes, lbry_uri, file_name, download_path,
|
2016-12-07 22:31:44 +01:00
|
|
|
stopped, metadata, sd_hash} = fileInfo;
|
2016-07-26 15:02:28 +02:00
|
|
|
|
2016-11-09 13:00:25 +01:00
|
|
|
if (!metadata || seenUris[lbry_uri]) {
|
2016-07-26 15:02:28 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-07 17:29:08 +02:00
|
|
|
seenUris[lbry_uri] = true;
|
|
|
|
|
2016-06-27 22:38:08 +02:00
|
|
|
let {title, thumbnail} = metadata;
|
2016-05-16 10:19:41 +02:00
|
|
|
|
2016-08-03 12:43:10 +02:00
|
|
|
if (!fileInfo.pending && typeof metadata == 'object') {
|
|
|
|
var {title, thumbnail} = metadata;
|
|
|
|
var pending = false;
|
|
|
|
} else {
|
|
|
|
var title = null;
|
|
|
|
var thumbnail = null;
|
|
|
|
var pending = true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 10:19:41 +02:00
|
|
|
var ratioLoaded = written_bytes / total_bytes;
|
2016-09-02 10:50:44 +02:00
|
|
|
|
|
|
|
var mediaType = lbry.getMediaType(metadata.content_type, file_name);
|
|
|
|
var showWatchButton = (mediaType == 'video');
|
2016-05-16 10:19:41 +02:00
|
|
|
|
2016-08-07 17:29:08 +02:00
|
|
|
content.push(<MyFilesRow key={lbry_uri} lbryUri={lbry_uri} title={title || ('lbry://' + lbry_uri)} completed={completed} stopped={stopped}
|
2016-05-30 14:54:08 +02:00
|
|
|
ratioLoaded={ratioLoaded} imgUrl={thumbnail} path={download_path}
|
2016-09-16 18:46:15 +02:00
|
|
|
showWatchButton={showWatchButton} pending={pending}
|
2016-11-09 13:00:25 +01:00
|
|
|
available={this.state.filesAvailable[sd_hash]} isMine={this.props.show == 'published'} />);
|
2016-05-10 12:36:54 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 10:19:41 +02:00
|
|
|
return (
|
2016-05-23 14:16:14 +02:00
|
|
|
<main className="page">
|
2016-08-08 05:31:21 +02:00
|
|
|
{content}
|
2016-05-16 10:19:41 +02:00
|
|
|
</main>
|
|
|
|
);
|
2016-05-10 12:36:54 +02:00
|
|
|
}
|
2016-06-27 22:38:08 +02:00
|
|
|
});
|
2016-11-22 21:19:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
export default MyFilesPage;
|