spee.ch/client/containers/AssetDisplay/view.jsx

74 lines
2.5 KiB
React
Raw Normal View History

2018-02-07 04:00:52 +01:00
import React from 'react';
2018-03-08 18:26:33 +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 (
<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>
<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>
<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
className='asset'
2018-02-07 04:00:52 +01:00
src={`/${claimId}/${name}.${fileExt}`}
alt={name} />
2018-02-07 04:00:52 +01:00
);
case 'image/gif':
return (
<img
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;