2017-04-23 16:01:00 +02:00
import React from 'react' ;
import lbry from 'lbry.js' ;
import lbryuri from 'lbryuri.js' ;
import Link from 'component/link' ;
2017-05-18 19:58:28 +02:00
import { Thumbnail , TruncatedText , Icon } from 'component/common' ;
2017-04-29 19:02:25 +02:00
import FilePrice from 'component/filePrice'
2017-05-02 07:25:31 +02:00
import UriIndicator from 'component/uriIndicator' ;
2017-04-23 16:01:00 +02:00
2017-05-09 00:22:27 +02:00
class FileCard extends React . Component {
2017-05-18 19:58:28 +02:00
componentWillMount ( ) {
2017-05-15 18:34:33 +02:00
this . resolve ( this . props )
}
componentWillReceiveProps ( nextProps ) {
this . resolve ( nextProps )
}
resolve ( props ) {
2017-05-09 22:12:48 +02:00
const {
2017-05-10 03:33:13 +02:00
isResolvingUri ,
2017-05-09 22:12:48 +02:00
resolveUri ,
claim ,
uri ,
2017-05-15 18:34:33 +02:00
} = props
2017-04-29 11:50:29 +02:00
2017-05-15 18:34:33 +02:00
if ( ! isResolvingUri && claim === undefined && uri ) {
2017-05-09 22:12:48 +02:00
resolveUri ( uri )
2017-04-23 16:01:00 +02:00
}
2017-04-29 11:50:29 +02:00
}
2017-05-15 18:34:33 +02:00
componentWillUnmount ( ) {
2017-05-18 19:58:28 +02:00
const {
isResolvingUri ,
cancelResolveUri ,
uri
} = this . props
if ( isResolvingUri ) {
cancelResolveUri ( uri )
}
2017-05-15 18:34:33 +02:00
}
2017-04-29 11:50:29 +02:00
handleMouseOver ( ) {
2017-04-23 16:01:00 +02:00
this . setState ( {
hovered : true ,
} ) ;
2017-04-29 11:50:29 +02:00
}
handleMouseOut ( ) {
2017-04-23 16:01:00 +02:00
this . setState ( {
hovered : false ,
} ) ;
2017-04-29 11:50:29 +02:00
}
render ( ) {
2017-04-23 16:01:00 +02:00
2017-05-02 06:48:16 +02:00
const {
2017-05-18 19:58:28 +02:00
claim ,
fileInfo ,
2017-05-02 06:48:16 +02:00
metadata ,
isResolvingUri ,
navigate ,
} = this . props
2017-04-29 11:50:29 +02:00
2017-04-23 16:01:00 +02:00
const uri = lbryuri . normalize ( this . props . uri ) ;
2017-05-10 03:33:13 +02:00
const title = ! isResolvingUri && metadata && metadata . title ? metadata . title : uri ;
const obscureNsfw = this . props . obscureNsfw && metadata && metadata . nsfw ;
2017-05-02 06:48:16 +02:00
let description = ""
2017-05-10 03:33:13 +02:00
if ( isResolvingUri ) {
2017-05-26 09:02:37 +02:00
description = _ _ ( "Loading..." )
2017-05-10 03:33:13 +02:00
} else if ( metadata && metadata . description ) {
description = metadata . description
2017-05-18 19:58:28 +02:00
} else if ( claim === null ) {
2017-05-26 09:02:37 +02:00
description = _ _ ( "This address contains no content." )
2017-05-02 06:48:16 +02:00
}
2017-04-23 16:01:00 +02:00
return (
2017-04-29 11:50:29 +02:00
< section className = { 'card card--small card--link ' + ( obscureNsfw ? 'card--obscured ' : '' ) } onMouseEnter = { this . handleMouseOver . bind ( this ) } onMouseLeave = { this . handleMouseOut . bind ( this ) } >
2017-04-23 16:01:00 +02:00
< div className = "card__inner" >
2017-05-06 18:31:47 +02:00
< Link onClick = { ( ) => navigate ( '/show' , { uri } ) } className = "card__link" >
2017-04-23 16:01:00 +02:00
< div className = "card__title-identity" >
< h5 title = { title } > < TruncatedText lines = { 1 } > { title } < / TruncatedText > < / h5 >
< div className = "card__subtitle" >
2017-05-18 19:58:28 +02:00
< span style = { { float : "right" } } >
< FilePrice uri = { uri } / >
{ fileInfo ? < span > { ' ' } < Icon fixed icon = "icon-folder" / > < / span > : '' }
< / span >
2017-05-02 07:25:31 +02:00
< UriIndicator uri = { uri } / >
2017-04-23 16:01:00 +02:00
< / div >
< / div >
2017-05-11 02:59:47 +02:00
{ metadata && metadata . thumbnail &&
2017-04-23 16:01:00 +02:00
< div className = "card__media" style = { { backgroundImage : "url('" + metadata . thumbnail + "')" } } > < / div >
2017-05-01 08:26:09 +02:00
}
2017-04-23 16:01:00 +02:00
< div className = "card__content card__subtext card__subtext--two-lines" >
2017-05-02 06:48:16 +02:00
< TruncatedText lines = { 2 } > { description } < / TruncatedText >
2017-04-23 16:01:00 +02:00
< / div >
2017-05-06 18:31:47 +02:00
< / Link >
2017-05-09 22:12:48 +02:00
{ obscureNsfw && this . state . hovered
2017-04-23 16:01:00 +02:00
? < div className = 'card-overlay' >
< p >
2017-05-26 09:02:37 +02:00
{ _ _ ( "This content is Not Safe For Work. To view adult content, please change your" ) } < Link className = "button-text" onClick = { ( ) => navigate ( 'settings' ) } label = { _ _ ( "Settings" ) } / > .
2017-04-23 16:01:00 +02:00
< / p >
< / div >
: null }
< / div >
< / section >
) ;
}
2017-04-29 11:50:29 +02:00
}
2017-04-23 16:01:00 +02:00
2017-05-09 00:22:27 +02:00
export default FileCard