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

129 lines
3.5 KiB
React
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import lbry from 'lbry.js';
import lbryuri from 'lbryuri.js';
2017-04-27 09:05:41 +02:00
import Video from 'component/video'
import {
Thumbnail,
} 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-12 19:14:06 +02:00
class FilePage extends React.Component{
2017-05-13 00:50:51 +02:00
componentDidMount() {
2017-05-12 19:14:06 +02:00
this.fetchFileInfo(this.props)
}
componentWillReceiveProps(nextProps) {
this.fetchFileInfo(nextProps)
}
fetchFileInfo(props) {
2017-05-13 00:50:51 +02:00
if (props.fileInfo === undefined) {
2017-05-15 05:50:59 +02:00
props.fetchFileInfo(props.uri)
2017-05-12 19:14:06 +02:00
}
}
render() {
const {
claim,
fileInfo,
2017-05-15 05:50:59 +02:00
metadata,
contentType,
2017-05-12 19:14:06 +02:00
uri,
} = this.props
2017-05-01 22:50:07 +02:00
2017-05-15 05:50:59 +02:00
if (!claim || !metadata) {
return <span className="empty">Empty claim or metadata info.</span>
}
const {
txid,
nout,
has_signature: hasSignature,
signature_is_valid: signatureIsValid,
value
} = claim
2017-05-01 22:50:07 +02:00
2017-05-15 05:50:59 +02:00
const outpoint = txid + ':' + nout
const title = metadata.title
2017-05-12 19:14:06 +02:00
const channelUriObj = lbryuri.parse(uri)
delete channelUriObj.path;
delete channelUriObj.contentName;
2017-05-15 05:50:59 +02:00
const channelUri = signatureIsValid && hasSignature && channelUriObj.isChannel ? lbryuri.build(channelUriObj, false) : null
2017-05-12 19:14:06 +02:00
const uriIndicator = <UriIndicator uri={uri} />
2017-05-01 22:50:07 +02:00
2017-05-12 19:14:06 +02:00
return (
<main className="main--single-column">
<section className="show-page-media">
{ contentType && contentType.startsWith('video/') ?
2017-05-15 05:50:59 +02:00
<Video className="video-embedded" uri={uri} /> :
2017-05-13 00:50:51 +02:00
(metadata && metadata.thumbnail ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
2017-05-12 19:14:06 +02:00
</section>
<section className="card">
<div className="card__inner">
<div className="card__title-identity">
2017-05-15 05:50:59 +02:00
{!fileInfo || fileInfo.written_bytes <= 0
2017-05-12 19:14:06 +02:00
? <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">
2017-05-15 05:50:59 +02:00
<FileActions uri={uri} />
</div>
2017-05-12 19:14:06 +02:00
</div>
<div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
2017-05-13 00:50:51 +02:00
{metadata && metadata.description}
2017-05-12 19:14:06 +02:00
</div>
2017-05-01 22:50:07 +02:00
</div>
2017-05-12 19:14:06 +02:00
{ metadata ?
<div className="card__content">
2017-05-15 05:50:59 +02:00
<FormatItem metadata={metadata} contentType={contentType} />
2017-05-12 19:14:06 +02:00
</div> : '' }
2017-05-05 07:10:37 +02:00
<div className="card__content">
2017-05-12 19:14:06 +02:00
<Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
</div>
</section>
</main>
)
}
2017-05-05 07:10:37 +02:00
}
2017-05-01 21:59:40 +02:00
export default FilePage;