more file tile refactor and fix file info unsubscribe
This commit is contained in:
parent
b7f23aa0dd
commit
e0eb36d032
5 changed files with 60 additions and 38 deletions
|
@ -124,7 +124,7 @@ export let Thumbnail = React.createClass({
|
||||||
_isMounted: false,
|
_isMounted: false,
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
src: React.PropTypes.string.isRequired,
|
src: React.PropTypes.string,
|
||||||
},
|
},
|
||||||
handleError: function() {
|
handleError: function() {
|
||||||
if (this.state.imageUrl != this._defaultImageUri) {
|
if (this.state.imageUrl != this._defaultImageUri) {
|
||||||
|
|
|
@ -168,7 +168,7 @@ export let FileActions = React.createClass({
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
this._isMounted = false;
|
this._isMounted = false;
|
||||||
if (this._fileInfoSubscribeId) {
|
if (this._fileInfoSubscribeId) {
|
||||||
lbry.fileInfoUnsubscribe(this.props.name, this._fileInfoSubscribeId);
|
lbry.fileInfoUnsubscribe(this.props.streamName, this._fileInfoSubscribeId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
|
@ -49,11 +49,10 @@ let FilePrice = React.createClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let FileTile = React.createClass({
|
/*should be merged into FileTile once FileTile is refactored to take a single id*/
|
||||||
_isMounted: false,
|
let FileTileStream = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
name: React.PropTypes.string,
|
metadata: React.PropTypes.object,
|
||||||
sdHash: React.PropTypes.string,
|
sdHash: React.PropTypes.string,
|
||||||
showPrice: React.PropTypes.bool,
|
showPrice: React.PropTypes.bool,
|
||||||
obscureNsfw: React.PropTypes.bool,
|
obscureNsfw: React.PropTypes.bool,
|
||||||
|
@ -62,12 +61,11 @@ let FileTile = React.createClass({
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
metadata: null,
|
|
||||||
title: null,
|
|
||||||
showNsfwHelp: false,
|
showNsfwHelp: false,
|
||||||
isRemoved: false
|
isRemoved: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
hideOnRemove: false,
|
hideOnRemove: false,
|
||||||
|
@ -76,7 +74,7 @@ let FileTile = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleMouseOver: function() {
|
handleMouseOver: function() {
|
||||||
if (this.props.obscureNsfw && this.state.metadata && this.state.metadata.nsfw) {
|
if (this.props.obscureNsfw && this.props.metadata && this.props.metadata.nsfw) {
|
||||||
this.setState({
|
this.setState({
|
||||||
showNsfwHelp: true,
|
showNsfwHelp: true,
|
||||||
});
|
});
|
||||||
|
@ -94,34 +92,20 @@ let FileTile = React.createClass({
|
||||||
isRemoved: true,
|
isRemoved: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
componentDidMount: function() {
|
|
||||||
this._isMounted = true;
|
|
||||||
|
|
||||||
lbry.resolveName(this.props.name, (metadata) => {
|
|
||||||
if (this._isMounted) {
|
|
||||||
this.setState({
|
|
||||||
metadata: metadata,
|
|
||||||
title: metadata && metadata.title ? metadata.title : ('lbry://' + this.props.name),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
this._isMounted = false;
|
|
||||||
},
|
|
||||||
render: function() {
|
render: function() {
|
||||||
if (this.state.metadata === null || (this.props.hideOnRemove && this.state.isRemoved)) {
|
if (this.props.metadata === null || (this.props.hideOnRemove && this.state.isRemoved)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const obscureNsfw = this.props.obscureNsfw && this.state.metadata.nsfw;
|
const metadata = this.props.metadata || {},
|
||||||
|
obscureNsfw = this.props.obscureNsfw && metadata.nsfw,
|
||||||
|
title = metadata.title ? metadata.title : ('lbry://' + this.props.name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={ 'file-tile card ' + (obscureNsfw ? 'card-obscured ' : '') } onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
|
<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="row-fluid card-content file-tile__row">
|
||||||
<div className="span3">
|
<div className="span3">
|
||||||
<a href={'/?show=' + this.props.name}><Thumbnail className="file-tile__thumbnail" src={this.state.metadata.thumbnail} alt={'Photo for ' + (this.state.metadata.title || this.props.name)} /></a>
|
<a href={'/?show=' + this.props.name}><Thumbnail className="file-tile__thumbnail" src={metadata.thumbnail} alt={'Photo for ' + (title || this.props.name)} /></a>
|
||||||
</div>
|
</div>
|
||||||
<div className="span9">
|
<div className="span9">
|
||||||
{ this.props.showPrice
|
{ this.props.showPrice
|
||||||
|
@ -131,29 +115,67 @@ let FileTile = React.createClass({
|
||||||
<h3 className="file-tile__title">
|
<h3 className="file-tile__title">
|
||||||
<a href={'/?show=' + this.props.name}>
|
<a href={'/?show=' + this.props.name}>
|
||||||
<TruncatedText lines={2}>
|
<TruncatedText lines={2}>
|
||||||
{this.state.metadata.title}
|
{title}
|
||||||
</TruncatedText>
|
</TruncatedText>
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
<FileActions streamName={this.props.name} metadata={this.state.metadata} />
|
<FileActions streamName={this.props.name} metadata={metadata} />
|
||||||
<p className="file-tile__description">
|
<p className="file-tile__description">
|
||||||
<TruncatedText lines={3}>
|
<TruncatedText lines={3}>
|
||||||
{this.state.metadata.description}
|
{metadata.description}
|
||||||
</TruncatedText>
|
</TruncatedText>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{this.state.showNsfwHelp
|
{this.state.showNsfwHelp
|
||||||
? <div className='card-overlay'>
|
? <div className='card-overlay'>
|
||||||
<p>
|
<p>
|
||||||
This content is Not Safe For Work.
|
This content is Not Safe For Work.
|
||||||
To view adult content, please change your <Link href="?settings" label="Settings" />.
|
To view adult content, please change your <Link href="?settings" label="Settings" />.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
: null}
|
: null}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let FileTile = React.createClass({
|
||||||
|
_isMounted: false,
|
||||||
|
|
||||||
|
propTypes: {
|
||||||
|
name: React.PropTypes.string
|
||||||
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
sdHash: null,
|
||||||
|
metadata: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount: function() {
|
||||||
|
this._isMounted = true;
|
||||||
|
|
||||||
|
lbry.resolveName(this.props.name, (metadata) => {
|
||||||
|
if (this._isMounted) {
|
||||||
|
this.setState({
|
||||||
|
sdHash: metadata.sources.lbry_sd_hash,
|
||||||
|
metadata: metadata,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
this._isMounted = false;
|
||||||
|
},
|
||||||
|
render: function() {
|
||||||
|
if (this.state.metadata === null || this.state.sdHash === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <FileTileStream name={this.props.name} sdHash={this.state.sdHash} metadata={this.state.metadata} />;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default FileTile;
|
export default FileTile;
|
|
@ -506,7 +506,7 @@ lbry.fileInfoSubscribeByName = function(name, callback) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
lbry.fileInfoUnsubscribe = function(name, subscribeId) {
|
lbry.fileInfoUnsubscribe = function(name, subscribeId) {
|
||||||
delete lbry._fileInfoSubscribeCallbacks[name][subscribeId];
|
lbry._fileInfoSubscribeCallbacks[name] = lbry._fileInfoSubscribeCallbacks[name].splice(subscribeId, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default lbry;
|
export default lbry;
|
||||||
|
|
|
@ -44,7 +44,7 @@ var SearchResults = React.createClass({
|
||||||
var rows = [];
|
var rows = [];
|
||||||
this.props.results.forEach(function({name, value}) {
|
this.props.results.forEach(function({name, value}) {
|
||||||
rows.push(
|
rows.push(
|
||||||
<FileTile key={name} name={name} sdHash={value.sources.lbry_sd_hash} metadata={value} />
|
<FileTile key={name} name={name} />
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Add table
Reference in a new issue