Refactor UriIndicator

This commit is contained in:
6ea86b96 2017-05-02 12:25:31 +07:00 committed by Jeremy Kauffman
parent 2547d85751
commit b97703dc3c
6 changed files with 72 additions and 51 deletions

View file

@ -1,43 +0,0 @@
import React from 'react';
import lbry from '../lbry.js';
import lbryuri from '../lbryuri.js';
import {Icon} from './common.js';
const UriIndicator = React.createClass({
propTypes: {
uri: React.PropTypes.string.isRequired,
hasSignature: React.PropTypes.bool.isRequired,
signatureIsValid: React.PropTypes.bool,
},
render: function() {
const uriObj = lbryuri.parse(this.props.uri);
if (!this.props.hasSignature || !uriObj.isChannel) {
return <span className="empty">Anonymous</span>;
}
const channelUriObj = Object.assign({}, uriObj);
delete channelUriObj.path;
delete channelUriObj.contentName;
const channelUri = lbryuri.build(channelUriObj, false);
let icon, modifier;
if (this.props.signatureIsValid) {
modifier = 'valid';
} else {
icon = 'icon-times-circle';
modifier = 'invalid';
}
return (
<span>
{channelUri} {' '}
{ !this.props.signatureIsValid ?
<Icon icon={icon} className={`channel-indicator__icon channel-indicator__icon--${modifier}`} /> :
'' }
</span>
);
}
});
export default UriIndicator;

View file

@ -4,7 +4,7 @@ import lbryuri from 'lbryuri.js';
import Link from 'component/link'; import Link from 'component/link';
import {Thumbnail, TruncatedText,} from 'component/common'; import {Thumbnail, TruncatedText,} from 'component/common';
import FilePrice from 'component/filePrice' import FilePrice from 'component/filePrice'
import UriIndicator from 'component/channel-indicator'; import UriIndicator from 'component/uriIndicator';
class FileCardStream extends React.Component { class FileCardStream extends React.Component {
constructor(props) { constructor(props) {
@ -86,8 +86,7 @@ class FileCardStream extends React.Component {
<h5 title={title}><TruncatedText lines={1}>{title}</TruncatedText></h5> <h5 title={title}><TruncatedText lines={1}>{title}</TruncatedText></h5>
<div className="card__subtitle"> <div className="card__subtitle">
{ !hidePrice ? <span style={{float: "right"}}><FilePrice uri={uri} /></span> : null} { !hidePrice ? <span style={{float: "right"}}><FilePrice uri={uri} /></span> : null}
<UriIndicator uri={uri} metadata={metadata} contentType={this.props.contentType} <UriIndicator uri={uri} />
hasSignature={this.props.hasSignature} signatureIsValid={this.props.signatureIsValid} />
</div> </div>
</div> </div>
{metadata && {metadata &&

View file

@ -5,7 +5,7 @@ import Link from 'component/link';
import FileActions from 'component/fileActions'; import FileActions from 'component/fileActions';
import {Thumbnail, TruncatedText,} from 'component/common.js'; import {Thumbnail, TruncatedText,} from 'component/common.js';
import FilePrice from 'component/filePrice' import FilePrice from 'component/filePrice'
import UriIndicator from 'component/channel-indicator.js'; import UriIndicator from 'component/uriIndicator';
/*should be merged into FileTile once FileTile is refactored to take a single id*/ /*should be merged into FileTile once FileTile is refactored to take a single id*/
class FileTileStream extends React.Component { class FileTileStream extends React.Component {
@ -71,6 +71,8 @@ class FileTileStream extends React.Component {
const title = isConfirmed ? metadata.title : uri; const title = isConfirmed ? metadata.title : uri;
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw; const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
console.debug(this.props)
return ( return (
<section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}> <section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
<div className={"row-fluid card__inner file-tile__row"}> <div className={"row-fluid card__inner file-tile__row"}>

View file

@ -0,0 +1,20 @@
import React from 'react'
import {
connect,
} from 'react-redux'
import {
makeSelectClaimForUri,
} from 'selectors/claims'
import UriIndicator from './view'
const makeSelect = () => {
const selectClaimForUri = makeSelectClaimForUri()
const select = (state, props) => ({
claim: selectClaimForUri(state, props),
})
return select
}
export default connect(makeSelect, null)(UriIndicator)

View file

@ -0,0 +1,44 @@
import React from 'react';
import lbry from 'lbry';
import lbryuri from 'lbryuri';
import {Icon} from 'component/common';
const UriIndicator = (props) => {
const {
uri,
claim: {
has_signature: hasSignature,
signature_is_valid: signatureIsValid,
} = {},
} = props
const uriObj = lbryuri.parse(uri);
if (!hasSignature || !uriObj.isChannel) {
return <span className="empty">Anonymous</span>;
}
const channelUriObj = Object.assign({}, uriObj);
delete channelUriObj.path;
delete channelUriObj.contentName;
const channelUri = lbryuri.build(channelUriObj, false);
let icon, modifier;
if (signatureIsValid) {
modifier = 'valid';
} else {
icon = 'icon-times-circle';
modifier = 'invalid';
}
return (
<span>
{channelUri} {' '}
{ !signatureIsValid ?
<Icon icon={icon} className={`channel-indicator__icon channel-indicator__icon--${modifier}`} /> :
'' }
</span>
)
}
export default UriIndicator;

View file

@ -11,7 +11,7 @@ import {
import FilePrice from 'component/filePrice' import FilePrice from 'component/filePrice'
import FileActions from 'component/fileActions'; import FileActions from 'component/fileActions';
import Link from 'component/link'; import Link from 'component/link';
import UriIndicator from 'component/channel-indicator.js'; import UriIndicator from 'component/uriIndicator';
const FormatItem = (props) => { const FormatItem = (props) => {
const { const {
@ -133,7 +133,7 @@ let FilePage = React.createClass({
<section className="card"> <section className="card">
<div className="card__inner"> <div className="card__inner">
<div className="card__title-identity"> <div className="card__title-identity">
{this.state.isDownloaded === false {isDownloaded === false
? <span style={{float: "right"}}><FilePrice uri={lbryuri.normalize(uri)} metadata={metadata} /></span> ? <span style={{float: "right"}}><FilePrice uri={lbryuri.normalize(uri)} metadata={metadata} /></span>
: null} : null}
<h1>{title}</h1> <h1>{title}</h1>
@ -143,8 +143,7 @@ let FilePage = React.createClass({
uriIndicator} uriIndicator}
</div> </div>
<div className="card__actions"> <div className="card__actions">
<FileActions uri={this.props.uri} outpoint={this.props.outpoint} metadata={metadata} contentType={this.props.contentType} /> <FileActions uri={uri} outpoint={outpoint} metadata={metadata} contentType={contentType} /></div>
</div>
</div> </div>
<div className="card__content card__subtext card__subtext card__subtext--allow-newlines"> <div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
{metadata.description} {metadata.description}