lbry-desktop/ui/js/page/show.js

197 lines
6.2 KiB
JavaScript
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import lbry from '../lbry.js';
2016-12-08 00:07:28 +01:00
import lighthouse from '../lighthouse.js';
2017-04-18 21:14:42 +02:00
import lbryuri from '../lbryuri.js';
2017-04-13 20:52:26 +02:00
import {Video} from '../page/watch.js'
import {TruncatedText, Thumbnail, FilePrice, BusyMessage} from '../component/common.js';
import {FileActions} from '../component/file-actions.js';
import {Link} from '../component/link.js';
2017-04-13 20:52:26 +02:00
import UriIndicator from '../component/channel-indicator.js';
2016-07-16 04:58:24 +02:00
var FormatItem = React.createClass({
propTypes: {
2017-04-11 03:29:07 +02:00
metadata: React.PropTypes.object,
contentType: React.PropTypes.string,
uri: React.PropTypes.string,
outpoint: React.PropTypes.string,
2016-07-16 04:58:24 +02:00
},
render: function() {
2017-04-11 03:29:07 +02:00
const {thumbnail, author, title, description, language, license} = this.props.metadata;
const mediaType = lbry.getMediaType(this.props.contentType);
2016-07-16 04:58:24 +02:00
if (!this.props.contentType && [author, language, license].filter().length === 0) {
return null;
}
2016-07-16 04:58:24 +02:00
return (
2017-04-13 20:52:26 +02:00
<table className="table-standard">
<tbody>
<tr>
<td>Content-Type</td><td>{this.props.contentType}</td>
</tr>
<tr>
<td>Author</td><td>{author}</td>
</tr>
<tr>
<td>Language</td><td>{language}</td>
</tr>
<tr>
<td>License</td><td>{license}</td>
</tr>
</tbody>
</table>
);
2016-07-16 04:58:24 +02:00
}
});
2017-04-13 20:52:26 +02:00
let ShowPage = React.createClass({
2017-04-11 03:29:07 +02:00
_uri: null,
_isMounted: false,
2017-04-11 03:29:07 +02:00
2016-07-16 04:58:24 +02:00
propTypes: {
2017-04-11 03:29:07 +02:00
uri: React.PropTypes.string,
2016-07-16 04:58:24 +02:00
},
getInitialState: function() {
return {
outpoint: null,
metadata: null,
2017-04-11 03:29:07 +02:00
contentType: null,
2017-04-13 20:52:26 +02:00
hasSignature: false,
signatureIsValid: false,
cost: null,
costIncludesData: null,
2017-04-11 03:29:07 +02:00
uriLookupComplete: null,
isDownloaded: null,
isFailed: false,
};
},
componentWillUnmount: function() {
this._isMounted = false;
},
componentWillReceiveProps: function(nextProps) {
if (nextProps.uri != this.props.uri) {
this.loadUri(nextProps.uri);
}
},
componentWillMount: function() {
this.loadUri(this.props.uri);
},
loadUri: function(uri) {
this._uri = lbryuri.normalize(uri);
2016-08-08 06:47:48 +02:00
lbry.resolve({uri: this._uri}).then((resolveData) => {
if (resolveData) {
let {claim: {txid, nout, has_signature, signature_is_valid, value: {stream: {metadata, source: {contentType}}}}} = resolveData;
const outpoint = txid + ':' + nout;
lbry.file_list({outpoint}).then((fileInfo) => {
this.setState({
isDownloaded: fileInfo.length > 0,
});
});
lbry.setTitle(metadata.title ? metadata.title : this._uri)
if (this._isMounted) {
this.setState({
outpoint: outpoint,
metadata: metadata,
hasSignature: has_signature,
signatureIsValid: signature_is_valid,
contentType: contentType,
uriLookupComplete: true,
});
}
lbry.getCostInfo(this._uri).then(({cost, includesData}) => {
if (this._isMounted) {
this.setState({
cost: cost,
costIncludesData: includesData,
});
}
});
} else {
if (this._isMounted) {
this.setState(Object.assign({}, this.getInitialState(), {
uriLookupComplete: true,
isFailed: true
}));
}
}
});
},
2016-07-16 04:58:24 +02:00
render: function() {
const metadata = this.state.metadata;
const title = metadata ? this.state.metadata.title : this._uri;
if (this.state.isFailed) {
return <main className="main--single-column">
<section className="card">
<div className="card__inner">
<div className="card__title-identity"><h1>{this._uri}</h1></div>
</div>
<div className="card__content">
<p>
This location is not yet in use.
{ ' ' }
<Link href="?publish" label="Put something here" />.
</p>
</div>
</section>
</main>
}
2016-07-16 04:58:24 +02:00
return (
<main className="main--single-column">
2017-04-13 20:52:26 +02:00
<section className="show-page-media">
2017-04-14 00:32:03 +02:00
{ this.state.contentType && this.state.contentType.startsWith('video/') ?
<Video className="video-embedded" uri={this._uri} metadata={metadata} outpoint={this.state.outpoint} /> :
2017-04-14 01:43:17 +02:00
(metadata ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
2017-04-13 20:52:26 +02:00
</section>
<section className="card">
<div className="card__inner">
<div className="card__title-identity">
{this.state.isDownloaded === false
? <span style={{float: "right"}}><FilePrice uri={this._uri} metadata={this.state.metadata} /></span>
: null}
2017-04-13 20:52:26 +02:00
<h1>{title}</h1>
{ this.state.uriLookupComplete && this.state.outpoint ?
2017-04-13 20:52:26 +02:00
<div>
<div className="card__subtitle">
<UriIndicator uri={this._uri} hasSignature={this.state.hasSignature} signatureIsValid={this.state.signatureIsValid} />
</div>
<div className="card__actions">
2017-04-13 21:37:41 +02:00
<FileActions uri={this._uri} outpoint={this.state.outpoint} metadata={metadata} contentType={this.state.contentType} />
2017-04-13 20:52:26 +02:00
</div>
</div> : '' }
</div>
2017-04-13 20:52:26 +02:00
{ this.state.uriLookupComplete ?
<div>
<div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
{metadata.description}
</div>
</div>
2017-04-14 01:43:17 +02:00
: <div className="card__content"><BusyMessage message="Loading magic decentralized data..." /></div> }
2017-04-13 20:52:26 +02:00
</div>
2017-04-14 01:43:17 +02:00
{ metadata ?
<div className="card__content">
<FormatItem metadata={metadata} contentType={this.state.contentType} cost={this.state.cost} uri={this._uri} outpoint={this.state.outpoint} costIncludesData={this.state.costIncludesData} />
</div> : '' }
2017-04-13 20:52:26 +02:00
<div className="card__content">
<Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
</div>
</section>
</main>
);
2016-07-16 04:58:24 +02:00
}
2016-11-22 21:19:08 +01:00
});
2017-04-11 03:29:07 +02:00
export default ShowPage;