2018-02-07 04:00:52 +01:00
import React from 'react' ;
2018-02-07 19:52:09 +01:00
import ProgressBar from 'components/ProgressBar' ;
2018-02-07 04:00:52 +01:00
import { LOCAL _CHECK , UNAVAILABLE , ERROR , AVAILABLE } from 'constants/asset_display_states' ;
class AssetDisplay extends React . Component {
componentDidMount ( ) {
2018-02-09 01:23:09 +01:00
const { asset : { claimData : { name , claimId } } } = this . props ;
this . props . onFileRequest ( name , claimId ) ;
2018-02-07 04:00:52 +01:00
}
render ( ) {
2018-02-09 01:23:09 +01:00
const { status , error , asset : { claimData : { name , claimId , contentType , fileExt , thumbnail } } } = this . props ;
2018-02-07 04:00:52 +01:00
return (
2018-02-24 19:05:28 +01:00
< div id = 'asset-display-component' >
2018-02-07 04:00:52 +01:00
{ ( status === LOCAL _CHECK ) &&
< div >
< p > Checking to see if Spee . ch has your asset locally ... < / p >
< / div >
}
{ ( status === UNAVAILABLE ) &&
< div >
< p > Sit tight , we ' re searching the LBRY blockchain for your asset ! < / p >
2018-02-24 19:05:28 +01:00
< ProgressBar size = { 12 } / >
< p > Curious what magic is happening here ? < a className = 'link--primary' target = 'blank' href = 'https://lbry.io/faq/what-is-lbry' > Learn more . < / a > < / p >
2018-02-07 04:00:52 +01:00
< / div >
}
{ ( status === ERROR ) &&
< div >
2018-02-24 19:05:28 +01:00
< p > Unfortunately , we couldn 't download your asset from LBRY. You can help us out by sharing the below error message in the <a className=' link -- primary ' href=' https : //discord.gg/YjYbwhS' target='_blank'>LBRY discord</a>.</p>
< i > < p id = 'error-message' > { error } < / p > < / i >
2018-02-07 04:00:52 +01:00
< / div >
}
{ ( status === AVAILABLE ) &&
( ( ) => {
switch ( contentType ) {
case 'image/jpeg' :
case 'image/jpg' :
case 'image/png' :
return (
< img
2018-02-24 19:05:28 +01:00
className = 'asset'
2018-02-07 04:00:52 +01:00
src = { ` / ${ claimId } / ${ name } . ${ fileExt } ` }
2018-02-24 19:05:28 +01:00
alt = { name } / >
2018-02-07 04:00:52 +01:00
) ;
case 'image/gif' :
return (
< img
2018-02-24 19:05:28 +01:00
className = 'asset'
2018-02-07 04:00:52 +01:00
src = { ` / ${ claimId } / ${ name } . ${ fileExt } ` }
alt = { name }
/ >
) ;
case 'video/mp4' :
return (
2018-03-04 21:17:03 +01:00
< video className = 'asset video' controls poster = { thumbnail } >
2018-02-07 04:00:52 +01:00
< source
src = { ` / ${ claimId } / ${ name } . ${ fileExt } ` }
/ >
< p > Your browser does not support the < code > video < / code > element . < / p >
< / video >
) ;
default :
return (
< p > Unsupported file type < / p >
) ;
}
} ) ( )
}
< / div >
) ;
}
} ;
export default AssetDisplay ;