Make FileTile look up its own download status if not provided
This commit is contained in:
parent
1b51b4e329
commit
ce82f8cc6f
1 changed files with 46 additions and 2 deletions
|
@ -4,6 +4,9 @@ import {Link, DownloadLink, WatchLink} from '../component/link.js';
|
||||||
import {Thumbnail, TruncatedText, CreditAmount} from '../component/common.js';
|
import {Thumbnail, TruncatedText, CreditAmount} from '../component/common.js';
|
||||||
|
|
||||||
let FileTile = React.createClass({
|
let FileTile = React.createClass({
|
||||||
|
_isMounted: false,
|
||||||
|
_statusCheckInterval: 5000,
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
name: React.PropTypes.string.isRequired,
|
name: React.PropTypes.string.isRequired,
|
||||||
mediaType: React.PropTypes.string.isRequired,
|
mediaType: React.PropTypes.string.isRequired,
|
||||||
|
@ -13,12 +16,38 @@ let FileTile = React.createClass({
|
||||||
cost: React.PropTypes.number,
|
cost: React.PropTypes.number,
|
||||||
costIncludesData: React.PropTypes.boolean,
|
costIncludesData: React.PropTypes.boolean,
|
||||||
},
|
},
|
||||||
|
updateFileInfo: function(progress=null) {
|
||||||
|
const updateStatusCallback = ((result) => {
|
||||||
|
if (!this._isMounted || 'fileInfo' in this.props) {
|
||||||
|
/**
|
||||||
|
* The component was unmounted, or a file info data structure has now been provided by the
|
||||||
|
* containing component.
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
fileInfo: result || null,
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => { this.updateFileInfo() }, this._statusCheckInterval);
|
||||||
|
});
|
||||||
|
|
||||||
|
if ('sdHash' in this.props) {
|
||||||
|
lbry.getFileInfoBySdHash(this.props.sdHash, updateStatusCallback);
|
||||||
|
} else if ('name' in this.props) {
|
||||||
|
lbry.getFileInfoByName(this.props.name, updateStatusCallback);
|
||||||
|
} else {
|
||||||
|
throw new Error("No progress, stream name or sd hash passed to FileTile");
|
||||||
|
}
|
||||||
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
downloading: false,
|
downloading: false,
|
||||||
isHovered: false,
|
isHovered: false,
|
||||||
cost: null,
|
cost: null,
|
||||||
costIncludesData: null,
|
costIncludesData: null,
|
||||||
|
fileInfo: 'fileInfo' in this.props ? this.props.fileInfo : null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
|
@ -51,8 +80,23 @@ let FileTile = React.createClass({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
componentDidMount: function() {
|
||||||
|
this._isMounted = true;
|
||||||
|
this.updateFileInfo();
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
this._isMounted = false;
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
let obscureNsfw = !lbry.getClientSetting('showNsfw') && this.props.nsfw;
|
const obscureNsfw = !lbry.getClientSetting('showNsfw') && this.props.nsfw;
|
||||||
|
|
||||||
|
let downloadLinkExtraProps = {};
|
||||||
|
if (this.state.fileInfo !== null) {
|
||||||
|
const {written_bytes, total_bytes, completed} = this.state.fileInfo;
|
||||||
|
downloadLinkExtraProps['progress'] = written_bytes / total_bytes;
|
||||||
|
downloadLinkExtraProps['downloading'] = !completed;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={ 'file-tile card ' + (obscureNsfw ? 'card-obscured ' : '') + (this.props.compact ? 'file-tile--compact' : '')} onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
|
<section className={ 'file-tile card ' + (obscureNsfw ? 'card-obscured ' : '') + (this.props.compact ? 'file-tile--compact' : '')} onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
|
||||||
<div className="row-fluid card-content file-tile__row">
|
<div className="row-fluid card-content file-tile__row">
|
||||||
|
@ -76,7 +120,7 @@ let FileTile = React.createClass({
|
||||||
<div>
|
<div>
|
||||||
{this.props.mediaType == 'video' ? <WatchLink streamName={this.props.name} button="primary" /> : null}
|
{this.props.mediaType == 'video' ? <WatchLink streamName={this.props.name} button="primary" /> : null}
|
||||||
{!this.props.isMine
|
{!this.props.isMine
|
||||||
? <DownloadLink streamName={this.props.name} button="text" />
|
? <DownloadLink streamName={this.props.name} button="text" {... downloadLinkExtraProps}/>
|
||||||
: null}
|
: null}
|
||||||
</div>
|
</div>
|
||||||
<p className="file-tile__description">
|
<p className="file-tile__description">
|
||||||
|
|
Loading…
Add table
Reference in a new issue