import React from 'react'; import ProgressBar from 'components/ProgressBar'; import Request from 'utils/request'; import { LOCAL_CHECK, SEARCHING, UNAVAILABLE, AVAILABLE } from 'constants/asset_display_states'; import PropTypes from 'prop-types'; class AssetDisplay extends React.Component { constructor (props) { super(props); this.state = { error : null, status: LOCAL_CHECK, }; this.isLocalFileAvailableOnServer = this.isLocalFileAvailableOnServer.bind(this); this.triggerGetAssetOnServer = this.triggerGetAssetOnServer.bind(this); } componentDidMount () { const that = this; this.isLocalFileAvailableOnServer() .then(isAvailable => { if (!isAvailable) { console.log('file is not yet available'); that.setState({status: SEARCHING}); return that.triggerGetAssetOnServer(); } }) .then(() => { that.setState({status: AVAILABLE}); }) .catch(error => { that.setState({ status: UNAVAILABLE, error : error.message, }); }); } isLocalFileAvailableOnServer () { console.log(`checking if file is available for ${this.props.name}#${this.props.claimId}`); const url = `/api/file-is-available/${this.props.name}/${this.props.claimId}`; return new Promise((resolve, reject) => { Request(url) .then(isAvailable => { console.log('/api/file-is-available response:', isAvailable); resolve(isAvailable); }) .catch(error => { reject(error); }); }); } triggerGetAssetOnServer () { console.log(`getting claim for ${this.props.name}#${this.props.claimId}`); const url = `/api/claim-get/${this.props.name}/${this.props.claimId}`; return new Promise((resolve, reject) => { Request(url) .then(response => { console.log('/api/claim-get response:', response); resolve(true); }) .catch(error => { reject(error); }); }); } render () { return (
{(this.state.status === SEARCHING) &&

Sit tight, we're searching the LBRY blockchain for your asset!

Curious what magic is happening here? Learn more.

} {(this.state.status === UNAVAILABLE) &&

Unfortunately, we couldn't download your asset from LBRY. You can help us out by sharing the below error message in the LBRY discord.

{this.state.error}

} {(this.state.status === AVAILABLE) && (() => { switch (this.props.contentType) { case 'image/jpeg': case 'image/jpg': case 'image/png': return ( {this.props.name}/ ); case 'image/gif': return ( {this.props.name}/ ); case 'video/mp4': return ( ); default: return (

Unsupported file type

); } })() }
); } }; AssetDisplay.propTypes = { name : PropTypes.string.isRequired, claimId : PropTypes.string.isRequired, src : PropTypes.string.isRequired, contentType: PropTypes.string.isRequired, fileExt : PropTypes.string.isRequired, thumbnail : PropTypes.string.isRequired, }; export default AssetDisplay;