lbry-desktop/ui/js/page/filePage/view.jsx

355 lines
10 KiB
React
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import lbry from 'lbry.js';
import lighthouse from 'lighthouse.js';
import lbryuri from 'lbryuri.js';
2017-04-27 09:05:41 +02:00
import Video from 'component/video'
import {
TruncatedText,
Thumbnail,
BusyMessage,
} from 'component/common';
import FilePrice from 'component/filePrice'
import FileActions from 'component/fileActions';
2017-04-07 07:15:22 +02:00
import Link from 'component/link';
2017-05-02 07:25:31 +02:00
import UriIndicator from 'component/uriIndicator';
2016-07-16 04:58:24 +02:00
2017-04-24 16:17:36 +02:00
const FormatItem = (props) => {
const {
contentType,
2017-04-25 07:47:21 +02:00
metadata: {
author,
language,
license,
2017-05-04 05:44:08 +02:00
}
2017-04-24 16:17:36 +02:00
} = props
2017-05-04 05:44:08 +02:00
2017-04-24 16:17:36 +02:00
const mediaType = lbry.getMediaType(contentType);
2017-04-24 16:17:36 +02:00
return (
<table className="table-standard">
<tbody>
<tr>
2017-05-04 05:44:08 +02:00
<td>Content-Type</td><td>{mediaType}</td>
2017-04-24 16:17:36 +02:00
</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-05-05 07:10:37 +02:00
const FilePage = (props) => {
const {
claim,
navigate,
claim: {
txid,
nout,
has_signature: hasSignature,
signature_is_valid: signatureIsValid,
value,
value: {
stream,
stream: {
metadata,
source,
metadata: {
title,
} = {},
source: {
contentType,
} = {},
} = {},
} = {},
},
uri,
isDownloaded,
fileInfo,
costInfo,
costInfo: {
cost,
includesData: costIncludesData,
} = {},
} = props
2017-05-01 22:50:07 +02:00
2017-05-05 07:10:37 +02:00
const outpoint = txid + ':' + nout;
const uriLookupComplete = !!claim && Object.keys(claim).length
2017-05-01 22:50:07 +02:00
2017-05-05 07:10:37 +02:00
const channelUriObj = lbryuri.parse(uri)
delete channelUriObj.path;
delete channelUriObj.contentName;
const channelUri = signatureIsValid && hasSignature && channelUriObj.isChannel ? lbryuri.build(channelUriObj, false) : null;
const uriIndicator = <UriIndicator uri={uri} />
2017-05-01 22:50:07 +02:00
2017-05-05 07:10:37 +02:00
return (
<main className="main--single-column">
<section className="show-page-media">
{ contentType && contentType.startsWith('video/') ?
<Video className="video-embedded" uri={uri} metadata={metadata} outpoint={outpoint} /> :
(Object.keys(metadata).length > 0 ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
</section>
<section className="card">
<div className="card__inner">
<div className="card__title-identity">
{isDownloaded === false
? <span style={{float: "right"}}><FilePrice uri={lbryuri.normalize(uri)} /></span>
: null}
<h1>{title}</h1>
<div className="card__subtitle">
{ channelUri ?
<Link href={"?show=" + channelUri }>{uriIndicator}</Link> :
uriIndicator}
</div>
<div className="card__actions">
<FileActions uri={uri} /></div>
2017-05-01 22:50:07 +02:00
</div>
2017-05-05 07:10:37 +02:00
<div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
{metadata.description}
2017-05-01 22:50:07 +02:00
</div>
2017-05-05 07:10:37 +02:00
</div>
{ metadata ?
<div className="card__content">
<FormatItem metadata={metadata} contentType={contentType} cost={cost} uri={uri} outpoint={outpoint} costIncludesData={costIncludesData} />
</div> : '' }
<div className="card__content">
<Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
</div>
</section>
</main>
)
}
2017-05-01 21:59:40 +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,
2017-05-01 21:59:40 +02:00
claimType: null,
2017-04-13 20:52:26 +02:00
signatureIsValid: false,
cost: null,
costIncludesData: null,
2017-04-11 03:29:07 +02:00
uriLookupComplete: null,
isFailed: false,
};
},
componentWillUnmount: function() {
this._isMounted = false;
},
componentWillReceiveProps: function(nextProps) {
if (nextProps.uri != this.props.uri) {
2017-05-01 22:50:07 +02:00
this.setState(this.getInitialState());
this.loadUri(nextProps.uri);
}
},
componentWillMount: function() {
2017-05-01 21:59:40 +02:00
this._isMounted = true;
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) => {
2017-05-01 21:59:40 +02:00
const isChannel = resolveData && resolveData.claims_in_channel;
if (!this._isMounted) {
return;
}
if (resolveData) {
2017-05-01 21:59:40 +02:00
let newState = { uriLookupComplete: true }
if (!isChannel) {
let {claim: {txid: txid, nout: nout, has_signature: has_signature, signature_is_valid: signature_is_valid, value: {stream: {metadata: metadata, source: {contentType: contentType}}}}} = resolveData;
2017-05-01 21:59:40 +02:00
Object.assign(newState, {
claimType: "file",
metadata: metadata,
2017-05-01 21:59:40 +02:00
outpoint: txid + ':' + nout,
hasSignature: has_signature,
signatureIsValid: signature_is_valid,
2017-05-01 21:59:40 +02:00
contentType: contentType
});
2017-05-01 21:59:40 +02:00
lbry.setTitle(metadata.title ? metadata.title : this._uri)
} else {
let {certificate: {txid: txid, nout: nout, has_signature: has_signature}} = resolveData;
Object.assign(newState, {
claimType: "channel",
outpoint: txid + ':' + nout,
txid: txid,
metadata: {
title:resolveData.certificate.name
}
});
}
2017-05-01 21:59:40 +02:00
this.setState(newState);
} else {
this.setState(Object.assign({}, this.getInitialState(), {
uriLookupComplete: true,
isFailed: true
}));
}
});
},
2016-07-16 04:58:24 +02:00
render: function() {
2017-05-01 21:59:40 +02:00
const metadata = this.state.metadata,
title = metadata ? this.state.metadata.title : this._uri;
2017-05-01 21:59:40 +02:00
2017-05-01 22:50:07 +02:00
let innerContent = "";
2017-05-01 22:50:07 +02:00
if (!this.state.uriLookupComplete || this.state.isFailed) {
innerContent = <section className="card">
<div className="card__inner">
<div className="card__title-identity"><h1>{title}</h1></div>
</div>
<div className="card__content">
{ this.state.uriLookupComplete ?
<p>This location is not yet in use. { ' ' }<Link href="?publish" label="Put something here" />.</p> :
<BusyMessage message="Loading magic decentralized data..." />
}
</div>
2017-05-01 22:50:07 +02:00
</section>;
} else {
let channelUriObj = lbryuri.parse(this._uri)
delete channelUriObj.path;
delete channelUriObj.contentName;
const channelUri = this.state.signatureIsValid && this.state.hasSignature && channelUriObj.isChannel ? lbryuri.build(channelUriObj, false) : null;
innerContent = <FilePage
uri={this._uri}
channelUri={channelUri}
outpoint={this.state.outpoint}
metadata={metadata}
contentType={this.state.contentType}
hasSignature={this.state.hasSignature}
signatureIsValid={this.state.signatureIsValid}
/>;
}
2017-05-01 22:50:07 +02:00
return <main className="main--single-column">{innerContent}</main>;
2016-07-16 04:58:24 +02:00
}
});
2017-05-04 05:44:08 +02:00
export default FilePage;
//
// const ShowPage = (props) => {
// const {
// claim,
// navigate,
// claim: {
// txid,
// nout,
// has_signature: hasSignature,
// signature_is_valid: signatureIsValid,
// value,
// value: {
// stream,
// stream: {
// metadata,
// source,
// metadata: {
// title,
// } = {},
// source: {
// contentType,
// } = {},
// } = {},
// } = {},
// },
// uri,
// isDownloaded,
// fileInfo,
// costInfo,
// costInfo: {
// cost,
// includesData: costIncludesData,
// } = {},
// } = props
//
// const outpoint = txid + ':' + nout;
// const uriLookupComplete = !!claim && Object.keys(claim).length
//
// if (props.isFailed) {
// return (
// <main className="main--single-column">
// <section className="card">
// <div className="card__inner">
// <div className="card__title-identity"><h1>{uri}</h1></div>
// </div>
// <div className="card__content">
// <p>
// This location is not yet in use.
// { ' ' }
// <Link href="#" onClick={() => navigate('publish')} label="Put something here" />.
// </p>
// </div>
// </section>
// </main>
// )
// }
//
// return (
// <main className="main--single-column">
// <section className="show-page-media">
// { contentType && contentType.startsWith('video/') ?
// <Video className="video-embedded" uri={uri} metadata={metadata} outpoint={outpoint} /> :
// (metadata ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
// </section>
// <section className="card">
// <div className="card__inner">
// <div className="card__title-identity">
// {isDownloaded === false
// ? <span style={{float: "right"}}><FilePrice uri={lbryuri.normalize(uri)} /></span>
// : null}
// <h1>{title}</h1>
// { uriLookupComplete ?
// <div>
// <div className="card__subtitle">
// <UriIndicator uri={uri} />
// </div>
// <div className="card__actions">
// <FileActions uri={uri} outpoint={outpoint} metadata={metadata} contentType={contentType} />
// </div>
// </div> : '' }
// </div>
// { uriLookupComplete ?
// <div>
// <div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
// {metadata.description}
// </div>
// </div>
// : <div className="card__content"><BusyMessage message="Loading magic decentralized data..." /></div> }
// </div>
// { metadata ?
// <div className="card__content">
// <FormatItem metadata={metadata} contentType={contentType} cost={cost} uri={uri} outpoint={outpoint} costIncludesData={costIncludesData} />
// </div> : '' }
// <div className="card__content">
// <Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
// </div>
// </section>
// </main>
// )
// }