import React from 'react'; import lbry from '../lbry.js'; import {Link} from '../component/link.js'; import {FileActions} from '../component/file-actions.js'; import {Thumbnail, TruncatedText, CreditAmount} from '../component/common.js'; import ChannelIndicator from '../component/channel-indicator.js'; let FilePrice = React.createClass({ _isMounted: false, propTypes: { uri: React.PropTypes.string }, getInitialState: function() { return { cost: null, costIncludesData: null, } }, componentDidMount: function() { this._isMounted = true; lbry.getCostInfoForName(this.props.uri, ({cost, includesData}) => { if (this._isMounted) { this.setState({ cost: cost, costIncludesData: includesData, }); } }, () => { // If we get an error looking up cost information, do nothing }); }, componentWillUnmount: function() { this._isMounted = false; }, render: function() { if (this.state.cost === null) { return null; } return ( ); } }); /*should be merged into FileTile once FileTile is refactored to take a single id*/ export let FileTileStream = React.createClass({ _fileInfoSubscribeId: null, _isMounted: null, _metadata: null, propTypes: { uri: React.PropTypes.string, claimInfo: React.PropTypes.object, outpoint: React.PropTypes.string, hideOnRemove: React.PropTypes.bool, hidePrice: React.PropTypes.bool, obscureNsfw: React.PropTypes.bool }, getInitialState: function() { return { showNsfwHelp: false, isHidden: false, available: null, } }, getDefaultProps: function() { return { obscureNsfw: !lbry.getClientSetting('showNsfw'), hidePrice: false } }, componentWillMount: function() { const {value: {stream: {metadata, source: {contentType}}}} = this.props.claimInfo; this._metadata = metadata; this._contentType = contentType; }, componentDidMount: function() { this._isMounted = true; if (this.props.hideOnRemove) { this._fileInfoSubscribeId = lbry.fileInfoSubscribe(this.props.outpoint, this.onFileInfoUpdate); } }, componentWillUnmount: function() { if (this._fileInfoSubscribeId) { lbry.fileInfoUnsubscribe(this.props.outpoint, this._fileInfoSubscribeId); } }, onFileInfoUpdate: function(fileInfo) { if (!fileInfo && this._isMounted && this.props.hideOnRemove) { this.setState({ isHidden: true }); } }, handleMouseOver: function() { if (this.props.obscureNsfw && this.props.metadata && this._metadata.nsfw) { this.setState({ showNsfwHelp: true, }); } }, handleMouseOut: function() { if (this.state.showNsfwHelp) { this.setState({ showNsfwHelp: false, }); } }, render: function() { if (this.state.isHidden) { return null; } const metadata = this._metadata; const isConfirmed = typeof metadata == 'object'; const title = isConfirmed ? metadata.title : ('lbry://' + this.props.uri); const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw; return ( { !this.props.hidePrice ? : null} {'lbry://' + this.props.uri} {title} {isConfirmed ? metadata.description : This file is pending confirmation.} {this.state.showNsfwHelp ? This content is Not Safe For Work. To view adult content, please change your . : null} ); } }); export let FileTile = React.createClass({ _isMounted: false, propTypes: { uri: React.PropTypes.string.isRequired, available: React.PropTypes.bool, }, getInitialState: function() { return { outpoint: null, claimInfo: null } }, componentDidMount: function() { this._isMounted = true; lbry.resolve({uri: this.props.uri}).then(({claim: claimInfo}) => { const {value: {stream: {metadata}}, txid, nout} = claimInfo; if (this._isMounted && claimInfo.value.stream.metadata) { // In case of a failed lookup, metadata will be null, in which case the component will never display this.setState({ outpoint: txid + ':' + nout, claimInfo: claimInfo, }); } }); }, componentWillUnmount: function() { this._isMounted = false; }, render: function() { if (!this.state.claimInfo || !this.state.outpoint) { return null; } return ; } });
{isConfirmed ? metadata.description : This file is pending confirmation.}
This content is Not Safe For Work. To view adult content, please change your .