Add new channel auth status indicator to file tiles

This commit is contained in:
Alex Liebowitz 2017-04-08 02:34:51 -04:00
parent 3e2b675e7b
commit 461f5f95d9
3 changed files with 41 additions and 27 deletions

View file

@ -70,6 +70,7 @@ let FileActionsRow = React.createClass({
streamName: React.PropTypes.string,
outpoint: React.PropTypes.string.isRequired,
metadata: React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.string]),
contentType: React.PropTypes.string,
},
getInitialState: function() {
return {
@ -197,7 +198,7 @@ let FileActionsRow = React.createClass({
return (
<div>
{this.props.metadata.content_type && this.props.metadata.content_type.startsWith('video/')
{this.props.contentType && this.props.contentType.startsWith('video/')
? <WatchLink streamName={this.props.streamName} downloadStarted={!!this.state.fileInfo} />
: null}
{this.state.fileInfo !== null || this.state.fileInfo.isMine
@ -236,6 +237,7 @@ export let FileActions = React.createClass({
streamName: React.PropTypes.string,
outpoint: React.PropTypes.string.isRequired,
metadata: React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.string]),
contentType: React.PropTypes.string,
},
getInitialState: function() {
return {
@ -289,7 +291,8 @@ export let FileActions = React.createClass({
return (<section className="file-actions">
{
fileInfo || this.state.available || this.state.forceShowActions
? <FileActionsRow outpoint={this.props.outpoint} metadata={this.props.metadata} streamName={this.props.streamName} />
? <FileActionsRow outpoint={this.props.outpoint} metadata={this.props.metadata} streamName={this.props.streamName}
contentType={this.props.contentType} />
: <div>
<div className="button-set-item empty">This file is not currently available.</div>
<ToolTip label="Why?"

View file

@ -3,12 +3,13 @@ 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: {
name: React.PropTypes.string
uri: React.PropTypes.string
},
getInitialState: function() {
@ -21,7 +22,7 @@ let FilePrice = React.createClass({
componentDidMount: function() {
this._isMounted = true;
lbry.getCostInfoForName(this.props.name, ({cost, includesData}) => {
lbry.getCostInfoForName(this.props.uri, ({cost, includesData}) => {
if (this._isMounted) {
this.setState({
cost: cost,
@ -55,9 +56,11 @@ let FilePrice = React.createClass({
export let FileTileStream = React.createClass({
_fileInfoSubscribeId: null,
_isMounted: null,
_metadata: null,
propTypes: {
metadata: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.object]),
uri: React.PropTypes.string,
claimInfo: React.PropTypes.object,
outpoint: React.PropTypes.string,
hideOnRemove: React.PropTypes.bool,
hidePrice: React.PropTypes.bool,
@ -76,6 +79,11 @@ export let FileTileStream = React.createClass({
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) {
@ -95,7 +103,7 @@ export let FileTileStream = React.createClass({
}
},
handleMouseOver: function() {
if (this.props.obscureNsfw && this.props.metadata && this.props.metadata.nsfw) {
if (this.props.obscureNsfw && this.props.metadata && this._metadata.nsfw) {
this.setState({
showNsfwHelp: true,
});
@ -113,29 +121,30 @@ export let FileTileStream = React.createClass({
return null;
}
const metadata = this.props.metadata;
const metadata = this._metadata;
const isConfirmed = typeof metadata == 'object';
const title = isConfirmed ? metadata.title : ('lbry://' + this.props.name);
const title = isConfirmed ? metadata.title : ('lbry://' + this.props.uri);
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
return (
<section className={ 'file-tile card ' + (obscureNsfw ? 'card-obscured ' : '') } onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
<div className={"row-fluid card-content file-tile__row"}>
<div className="span3">
<a href={'?show=' + this.props.name}><Thumbnail className="file-tile__thumbnail" src={metadata.thumbnail} alt={'Photo for ' + (title || this.props.name)} /></a>
<a href={'?show=' + this.props.uri}><Thumbnail className="file-tile__thumbnail" src={metadata.thumbnail} alt={'Photo for ' + (title || this.props.uri)} /></a>
</div>
<div className="span9">
{ !this.props.hidePrice
? <FilePrice name={this.props.name} />
? <FilePrice uri={this.props.uri} />
: null}
<div className="meta"><a href={'?show=' + this.props.name}>{'lbry://' + this.props.name}</a></div>
<div className="meta"><a href={'?show=' + this.props.uri}>{'lbry://' + this.props.uri}</a></div>
<h3 className="file-tile__title">
<a href={'?show=' + this.props.name}>
<a href={'?show=' + this.props.uri}>
<TruncatedText lines={1}>
{title}
</TruncatedText>
</a>
</h3>
<FileActions streamName={this.props.name} outpoint={this.props.outpoint} metadata={metadata} />
<ChannelIndicator uri={this.props.uri} claimInfo={this.props.claimInfo} />
<FileActions uri={this.props.uri} outpoint={this.props.outpoint} metadata={metadata} contentType={this._contentType} />
<p className="file-tile__description">
<TruncatedText lines={3}>
{isConfirmed
@ -162,26 +171,27 @@ export let FileTile = React.createClass({
_isMounted: false,
propTypes: {
name: React.PropTypes.string.isRequired,
uri: React.PropTypes.string.isRequired,
available: React.PropTypes.bool,
},
getInitialState: function() {
return {
outpoint: null,
metadata: null
claimInfo: null
}
},
componentDidMount: function() {
this._isMounted = true;
lbry.claim_show({name: this.props.name}).then(({value, txid, nout}) => {
if (this._isMounted && value) {
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,
metadata: value,
claimInfo: claimInfo,
});
}
});
@ -190,10 +200,11 @@ export let FileTile = React.createClass({
this._isMounted = false;
},
render: function() {
if (!this.state.metadata || !this.state.outpoint) {
if (!this.state.claimInfo || !this.state.outpoint) {
return null;
}
return <FileTileStream outpoint={this.state.outpoint} metadata={this.state.metadata} {... this.props} />;
return <FileTileStream outpoint={this.state.outpoint} claimInfo={this.state.claimInfo}
{... this.props} uri={this.props.uri}/>;
}
});

View file

@ -48,7 +48,7 @@ var SearchResults = React.createClass({
if (!seenNames[name]) {
seenNames[name] = name;
rows.push(
<FileTile key={name} name={name} sdHash={value.sources.lbry_sd_hash} />
<FileTile key={name} uri={name} sdHash={value.sources.lbry_sd_hash} />
);
}
});
@ -84,18 +84,18 @@ var FeaturedContent = React.createClass({
<div className="row-fluid">
<div className="span6">
<h3>Featured Content</h3>
{ this.state.featuredNames.map((name) => { return <FileTile key={name} name={name} /> }) }
{ this.state.featuredNames.map((name) => { return <FileTile key={name} uri={name} /> }) }
</div>
<div className="span6">
<h3>
Community Content
<ToolTip label="What's this?" body={toolTipText} className="tooltip--header"/>
</h3>
<FileTile name="one" />
<FileTile name="two" />
<FileTile name="three" />
<FileTile name="four" />
<FileTile name="five" />
<FileTile uri="one" />
<FileTile uri="two" />
<FileTile uri="three" />
<FileTile uri="four" />
<FileTile uri="five" />
</div>
</div>
);