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-11 03:29:07 +02:00
import uri from '../uri.js' ;
2016-12-08 00:07:28 +01:00
import { CreditAmount , Thumbnail } from '../component/common.js' ;
2017-01-13 03:03:34 +01:00
import { FileActions } from '../component/file-actions.js' ;
import { Link } from '../component/link.js' ;
2016-11-22 21:19:08 +01:00
2016-08-08 06:47:48 +02:00
var formatItemImgStyle = {
2016-07-16 04:58:24 +02:00
maxWidth : '100%' ,
maxHeight : '100%' ,
display : 'block' ,
marginLeft : 'auto' ,
marginRight : 'auto' ,
marginTop : '5px' ,
} ;
var FormatItem = React . createClass ( {
propTypes : {
2017-04-11 03:29:07 +02:00
metadata : React . PropTypes . object ,
contentType : React . PropTypes . string ,
2016-12-08 00:45:18 +01:00
cost : React . PropTypes . number ,
2017-04-11 03:29:07 +02:00
uri : React . PropTypes . string ,
2017-03-08 08:17:16 +01:00
outpoint : React . PropTypes . string ,
2016-12-08 00:45:18 +01:00
costIncludesData : React . PropTypes . bool ,
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-12-08 00:45:18 +01:00
var costIncludesData = this . props . costIncludesData ;
var cost = this . props . cost || 0.0 ;
2016-07-16 19:14:06 +02:00
2016-07-16 04:58:24 +02:00
return (
2016-08-08 06:47:48 +02:00
< div className = "row-fluid" >
2016-07-16 04:58:24 +02:00
< div className = "span4" >
2016-11-11 13:57:01 +01:00
< Thumbnail src = { thumbnail } alt = { 'Photo for ' + title } style = { formatItemImgStyle } / >
2016-07-16 04:58:24 +02:00
< / d i v >
< div className = "span8" >
2016-08-08 06:47:48 +02:00
< p > { description } < / p >
2016-08-27 00:06:22 +02:00
< section >
< table className = "table-standard" >
< tbody >
< tr >
2017-04-11 03:29:07 +02:00
< td > Content - Type < / t d > < t d > { t h i s . p r o p s . c o n t e n t T y p e } < / t d >
2016-08-27 00:06:22 +02:00
< / t r >
< tr >
2016-12-08 00:45:18 +01:00
< td > Cost < /td><td><CreditAmount amount={cost} isEstimate={!costIncludesData}/ > < / t d >
2016-08-27 00:06:22 +02:00
< / t r >
< tr >
< td > Author < / t d > < t d > { a u t h o r } < / t d >
< / t r >
< tr >
< td > Language < / t d > < t d > { l a n g u a g e } < / t d >
< / t r >
< tr >
< td > License < / t d > < t d > { l i c e n s e } < / t d >
< / t r >
< / t b o d y >
< / t a b l e >
< / s e c t i o n >
2017-04-11 03:29:07 +02:00
< FileActions uri = { this . _uri } outpoint = { this . props . outpoint } metadata = { this . props . metadata } contentType = { this . props . contentType } / >
2016-11-02 17:13:20 +01:00
< section >
< Link href = "https://lbry.io/dmca" label = "report" className = "button-text-help" / >
< / s e c t i o n >
2016-07-16 04:58:24 +02:00
< / d i v >
< / d i v >
) ;
}
} ) ;
var FormatsSection = React . createClass ( {
propTypes : {
2017-04-11 03:29:07 +02:00
uri : React . PropTypes . string ,
outpoint : React . PropTypes . string ,
metadata : React . PropTypes . object ,
contentType : React . PropTypes . string ,
2016-12-08 00:45:18 +01:00
cost : React . PropTypes . number ,
costIncludesData : React . PropTypes . bool ,
2016-07-16 04:58:24 +02:00
} ,
render : function ( ) {
2017-04-11 03:29:07 +02:00
if ( this . props . metadata == null )
2016-07-16 19:14:06 +02:00
{
return (
< div >
2016-08-08 06:47:48 +02:00
< h2 > Sorry , no results found for "{name}" . < / h 2 >
2016-07-16 19:14:06 +02:00
< / d i v > ) ;
}
2016-07-16 04:58:24 +02:00
return (
2016-07-16 07:19:40 +02:00
< div >
2017-04-11 03:29:07 +02:00
< div className = "meta" > { this . props . uri } < / d i v >
< h2 > { this . props . metadata . title } < / h 2 >
2016-07-16 07:19:40 +02:00
{ / * I n f u t u r e , a n t i c i p a t e m u l t i p l e f o r m a t s , j u s t a g u e s s a t w h a t i t c o u l d l o o k l i k e
2017-04-11 03:29:07 +02:00
// var formats = this.props.metadata.formats
2016-07-16 07:19:40 +02:00
// return (<tbody>{formats.map(function(format,i){ */}
2017-04-11 03:29:07 +02:00
< FormatItem metadata = { this . props . metadata } contentType = { this . props . contentType } cost = { this . props . cost } uri = { this . props . uri } outpoint = { this . props . outpoint } costIncludesData = { this . props . costIncludesData } / >
2016-07-16 07:19:40 +02:00
{ /* })}</tbody>); */ }
< / d i v > ) ;
2016-07-16 04:58:24 +02:00
}
} ) ;
2017-04-11 03:29:07 +02:00
var ShowPage = React . createClass ( {
_uri : null ,
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
} ,
2016-07-16 19:14:06 +02:00
getInitialState : function ( ) {
return {
2016-12-08 00:45:18 +01:00
metadata : null ,
2017-04-11 03:29:07 +02:00
contentType : null ,
2016-12-08 00:45:18 +01:00
cost : null ,
2016-12-08 01:38:52 +01:00
costIncludesData : null ,
2017-04-11 03:29:07 +02:00
uriLookupComplete : null ,
2016-07-16 19:14:06 +02:00
} ;
} ,
componentWillMount : function ( ) {
2017-04-11 03:29:07 +02:00
this . _uri = uri . normalizeLbryUri ( this . props . uri ) ;
document . title = this . _uri ;
2016-08-08 06:47:48 +02:00
2017-04-11 03:29:07 +02:00
lbry . resolve ( { uri : this . _uri } ) . then ( ( { txid , nout , claim : { value : { stream : { metadata , source : { contentType } } } } } ) => {
2016-12-08 01:38:52 +01:00
this . setState ( {
2017-03-08 08:17:16 +01:00
outpoint : txid + ':' + nout ,
2017-04-11 03:29:07 +02:00
metadata : metadata ,
contentType : contentType ,
uriLookupComplete : true ,
2016-12-08 01:38:52 +01:00
} ) ;
} ) ;
2016-09-02 08:49:50 +02:00
2017-04-11 03:29:07 +02:00
lbry . getCostInfo ( this . _uri , ( { cost , includesData } ) => {
2016-12-08 01:38:52 +01:00
this . setState ( {
cost : cost ,
costIncludesData : includesData ,
} ) ;
2016-07-16 19:14:06 +02:00
} ) ;
} ,
2016-07-16 04:58:24 +02:00
render : function ( ) {
2016-12-08 00:45:18 +01:00
if ( this . state . metadata == null ) {
2016-07-16 19:14:06 +02:00
return null ;
}
2016-07-16 04:58:24 +02:00
return (
2016-08-08 06:47:48 +02:00
< main >
< section className = "card" >
2017-04-11 03:29:07 +02:00
{ this . state . uriLookupComplete ? (
< FormatsSection uri = { this . _uri } outpoint = { this . state . outpoint } metadata = { this . state . metadata } cost = { this . state . cost } costIncludesData = { this . state . costIncludesData } contentType = { this . state . contentType } / >
2016-09-02 08:49:50 +02:00
) : (
< div >
< h2 > No content < / h 2 >
2017-04-11 03:29:07 +02:00
There is no content available at < strong > { this . _uri } < /strong>. If you reached this page from a link within the LBRY interface, please <Link href="?report" label="report a bug" / > . Thanks !
2016-09-02 08:49:50 +02:00
< / d i v >
) }
2016-08-08 06:47:48 +02:00
< / s e c t i o n >
2016-07-16 04:58:24 +02:00
< / m a i n > ) ;
}
2016-11-22 21:19:08 +01:00
} ) ;
2017-04-11 03:29:07 +02:00
export default ShowPage ;