Add setting to hide unavailable content

This commit is contained in:
Alex Liebowitz 2017-01-19 04:58:11 -05:00
parent 2aa10261d9
commit 9d0aa0d8da
3 changed files with 38 additions and 8 deletions

View file

@ -64,7 +64,8 @@ export let FileTileStream = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
showNsfwHelp: false, showNsfwHelp: false,
isHidden: false isHidden: false,
available: null,
} }
}, },
getDefaultProps: function() { getDefaultProps: function() {
@ -73,6 +74,15 @@ export let FileTileStream = React.createClass({
hidePrice: false hidePrice: false
} }
}, },
componentWillMount: function() {
if (!('available' in this.props)) {
lbry.getPeersForBlobHash(this.props.sdHash, (peers) => {
this.setState({
available: peers.length > 0,
});
});
}
},
componentDidMount: function() { componentDidMount: function() {
this._isMounted = true; this._isMounted = true;
if (this.props.hideOnRemove) { if (this.props.hideOnRemove) {
@ -84,6 +94,9 @@ export let FileTileStream = React.createClass({
lbry.fileInfoUnsubscribe(this.props.sdHash, this._fileInfoSubscribeId); lbry.fileInfoUnsubscribe(this.props.sdHash, this._fileInfoSubscribeId);
} }
}, },
isAvailable: function() {
return 'available' in this.props ? this.props.available : this.state.available;
},
onFileInfoUpdate: function(fileInfo) { onFileInfoUpdate: function(fileInfo) {
if (!fileInfo && this._isMounted && this.props.hideOnRemove) { if (!fileInfo && this._isMounted && this.props.hideOnRemove) {
this.setState({ this.setState({
@ -106,7 +119,7 @@ export let FileTileStream = React.createClass({
} }
}, },
render: function() { render: function() {
if (this.state.isHidden) { if (this.state.isHidden || (!lbry.getClientSetting('showUnavailable') && !this.isAvailable())) {
return null; return null;
} }
@ -157,7 +170,8 @@ export let FileTile = React.createClass({
_isMounted: false, _isMounted: false,
propTypes: { propTypes: {
name: React.PropTypes.string.isRequired name: React.PropTypes.string.isRequired,
available: React.PropTypes.bool,
}, },
getInitialState: function() { getInitialState: function() {
@ -187,6 +201,7 @@ export let FileTile = React.createClass({
return null; return null;
} }
return <FileTileStream name={this.props.name} sdHash={this.state.sdHash} metadata={this.state.metadata} />; return <FileTileStream name={this.props.name} available={this.props.available} sdHash={this.state.sdHash}
metadata={this.state.metadata} />;
} }
}); });

View file

@ -43,11 +43,11 @@ var SearchResults = React.createClass({
render: function() { render: function() {
var rows = [], var rows = [],
seenNames = {}; //fix this when the search API returns claim IDs seenNames = {}; //fix this when the search API returns claim IDs
this.props.results.forEach(function({name, value}) { this.props.results.forEach(function({name, peer_count}) {
if (!seenNames[name]) { if (!seenNames[name]) {
seenNames[name] = name; seenNames[name] = name;
rows.push( rows.push(
<FileTile key={name} name={name} /> <FileTile key={name} name={name} available={peer_count > 0} />
); );
} }
}); });

View file

@ -51,7 +51,8 @@ var SettingsPage = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
settings: null, settings: null,
showNsfw: lbry.getClientSetting('showNsfw') showNsfw: lbry.getClientSetting('showNsfw'),
showUnavailable: lbry.getClientSetting('showUnavailable'),
} }
}, },
componentDidMount: function() { componentDidMount: function() {
@ -69,6 +70,9 @@ var SettingsPage = React.createClass({
onShowNsfwChange: function(event) { onShowNsfwChange: function(event) {
lbry.setClientSetting('showNsfw', event.target.checked); lbry.setClientSetting('showNsfw', event.target.checked);
}, },
onShowUnavailableChange: function(event) {
lbry.setClientSetting('showUnavailable', event.target.checked);
},
render: function() { render: function() {
if (!this.state.daemonSettings) { if (!this.state.daemonSettings) {
return null; return null;
@ -114,7 +118,7 @@ var SettingsPage = React.createClass({
<h3>Content</h3> <h3>Content</h3>
<div className="form-row"> <div className="form-row">
<label style={settingsCheckBoxOptionStyles}> <label style={settingsCheckBoxOptionStyles}>
<input type="checkbox" onChange={this.onShowNsfwChange} defaultChecked={this.state.showNsfw} /> Show NSFW Content <input type="checkbox" onChange={this.onShowNsfwChange} defaultChecked={this.state.showNsfw} /> Show NSFW content
</label> </label>
<div className="help"> <div className="help">
NSFW content may include nudity, intense sexuality, profanity, or other adult content. NSFW content may include nudity, intense sexuality, profanity, or other adult content.
@ -122,6 +126,17 @@ var SettingsPage = React.createClass({
</div> </div>
</div> </div>
</section> </section>
<section className="card">
<h3>Search</h3>
<div className="form-row">
<div className="help">
Would you like search results to include items that are not currently available for download?
</div>
<label style={settingsCheckBoxOptionStyles}>
<input type="checkbox" onChange={this.onShowUnavailableChange} defaultChecked={this.state.showUnavailable} /> Show unavailable content in search results
</label>
</div>
</section>
<section className="card"> <section className="card">
<h3>Share Diagnostic Data</h3> <h3>Share Diagnostic Data</h3>
<label style={settingsCheckBoxOptionStyles}> <label style={settingsCheckBoxOptionStyles}>