Merge remote-tracking branch 'origin/show-hide-nsfw' into blur-nsfw
This commit is contained in:
commit
b53a178338
3 changed files with 83 additions and 46 deletions
43
js/lbry.js
43
js/lbry.js
|
@ -4,6 +4,9 @@ var lbry = {
|
|||
daemonConnectionString: 'http://localhost:5279/lbryapi',
|
||||
colors: {
|
||||
primary: '#155B4A'
|
||||
},
|
||||
defaultClientSettings: {
|
||||
showNsfw: false,
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -90,13 +93,20 @@ lbry.getNewAddress = function(callback) {
|
|||
lbry.call('get_new_address', {}, callback);
|
||||
}
|
||||
|
||||
lbry.getSettings = function(callback) {
|
||||
lbry.getDaemonSettings = function(callback) {
|
||||
lbry.call('get_settings', {}, callback);
|
||||
};
|
||||
}
|
||||
|
||||
lbry.setSettings = function(settings, callback) {
|
||||
lbry.setDaemonSettings = function(settings, callback) {
|
||||
lbry.call('set_settings', settings, callback);
|
||||
};
|
||||
}
|
||||
|
||||
lbry.setDaemonSetting = function(setting, value, callback) {
|
||||
var setSettingsArgs = {};
|
||||
setSettingsArgs[setting] = value;
|
||||
lbry.call('set_settings', setSettingsArgs, callback)
|
||||
}
|
||||
|
||||
|
||||
lbry.getBalance = function(callback)
|
||||
{
|
||||
|
@ -208,6 +218,31 @@ lbry.checkNewVersionAvailable = function(callback) {
|
|||
});
|
||||
}
|
||||
|
||||
lbry.getClientSettings = function() {
|
||||
var outSettings = {};
|
||||
for (let setting of Object.keys(lbry.defaultClientSettings)) {
|
||||
var localStorageVal = localStorage.getItem('setting_' + setting);
|
||||
outSettings[setting] = (localStorageVal === null ? lbry.defaultClientSettings[setting] : JSON.parse(localStorageVal));
|
||||
}
|
||||
return outSettings;
|
||||
}
|
||||
|
||||
lbry.getClientSetting = function(setting) {
|
||||
var localStorageVal = localStorage.getItem('setting_' + setting);
|
||||
return (localStorageVal === null ? lbry.defaultClientSettings[setting] : JSON.parse(localStorageVal));
|
||||
}
|
||||
|
||||
lbry.setClientSettings = function(settings) {
|
||||
for (let setting of Object.keys(settings)) {
|
||||
lbry.setClientSetting(setting, settings[setting]);
|
||||
}
|
||||
}
|
||||
|
||||
lbry.setClientSetting = function(setting, value) {
|
||||
return localStorage.setItem('setting_' + setting, JSON.stringify(value));
|
||||
}
|
||||
|
||||
|
||||
lbry.reportBug = function(message, callback) {
|
||||
lbry.call('upload_log', {
|
||||
name_prefix: 'report',
|
||||
|
|
|
@ -34,9 +34,10 @@ var SearchNoResults = React.createClass({
|
|||
|
||||
var SearchResults = React.createClass({
|
||||
render: function() {
|
||||
var showNsfw = lbry.getClientSetting('showNsfw');
|
||||
var rows = [];
|
||||
this.props.results.forEach(function(result) {
|
||||
if (!result.value.nsfw || lbry.setSettings(settings)['show_nsfw']) {
|
||||
if (showNsfw || !result.value.nsfw) {
|
||||
rows.push(
|
||||
<SearchResultRow key={result.name} name={result.name} title={result.value.title} imgUrl={result.value.thumbnail}
|
||||
description={result.value.description} cost={result.cost} />
|
||||
|
@ -157,10 +158,10 @@ var FeaturedContentItem = React.createClass({
|
|||
return null;
|
||||
}
|
||||
|
||||
//@TODO: Make this check the "show NSFW" setting once it's implemented
|
||||
var blur = !lbry.getClientSetting('showNsfw') && this.state.metadata.nsfw;
|
||||
|
||||
return (<div style={featuredContentItemContainerStyle} onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
|
||||
<div className={this.state.metadata.nsfw ? 'blur' : ''}>
|
||||
<div className={blur ? 'blur' : ''}>
|
||||
<SearchResultRow name={this.props.name} title={this.state.title} imgUrl={this.state.metadata.thumbnail}
|
||||
description={this.state.metadata.description} cost={this.state.amount}
|
||||
available={this.state.available} />
|
||||
|
@ -206,17 +207,25 @@ var DiscoverPage = React.createClass({
|
|||
componentDidUpdate: function() {
|
||||
if (this.props.query != this.state.query)
|
||||
{
|
||||
this.handleSearchChanged();
|
||||
}
|
||||
},
|
||||
|
||||
handleSearchChanged: function() {
|
||||
this.setState({
|
||||
searching: true,
|
||||
query: this.props.query,
|
||||
});
|
||||
|
||||
lbry.search(this.props.query, this.searchCallback);
|
||||
}
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
document.title = "Discover";
|
||||
if (this.props.query !== '') {
|
||||
// Rendering with a query already typed
|
||||
this.handleSearchChanged();
|
||||
}
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
|
|
|
@ -14,88 +14,75 @@ var settingsRadioOptionStyles = {
|
|||
};
|
||||
|
||||
var SettingsPage = React.createClass({
|
||||
storeSetting: function(setting, val) {
|
||||
var settings = Object.assign({}, this.state.settings);
|
||||
settings[setting] = val;
|
||||
this.setState({
|
||||
'settings': settings
|
||||
});
|
||||
lbry.setSettings(settings);
|
||||
},
|
||||
onRunOnNsfwChange: function (event) {
|
||||
this.storeSetting('show_nsfw', event.target.checked);
|
||||
},
|
||||
onRunOnStartChange: function (event) {
|
||||
this.storeSetting('run_on_startup', event.target.checked);
|
||||
lbry.setDaemonSetting('run_on_startup', event.target.checked);
|
||||
},
|
||||
onShareDataChange: function (event) {
|
||||
this.storeSetting('upload_log', event.target.checked);
|
||||
lbry.setDaemonSetting('upload_log', event.target.checked);
|
||||
},
|
||||
onDownloadDirChange: function(event) {
|
||||
this.storeSetting('download_directory', event.target.value);
|
||||
lbry.setDaemonSetting('download_directory', event.target.value);
|
||||
},
|
||||
onMaxUploadPrefChange: function(isLimited) {
|
||||
if (!isLimited) {
|
||||
this.storeSetting('max_upload', 0.0);
|
||||
lbry.setDaemonSetting('max_upload', 0.0);
|
||||
}
|
||||
this.setState({
|
||||
isMaxUpload: isLimited
|
||||
});
|
||||
},
|
||||
onMaxUploadFieldChange: function(event) {
|
||||
this.storeSetting('max_upload', Number(event.target.value));
|
||||
lbry.setDaemonSetting('max_upload', Number(event.target.value));
|
||||
},
|
||||
onMaxDownloadPrefChange: function(isLimited) {
|
||||
if (!isLimited) {
|
||||
this.storeSetting('max_download', 0.0);
|
||||
lbry.setDaemonSetting('max_download', 0.0);
|
||||
}
|
||||
this.setState({
|
||||
isMaxDownload: isLimited
|
||||
});
|
||||
},
|
||||
onMaxDownloadFieldChange: function(event) {
|
||||
this.storeSetting('max_download', Number(event.target.value));
|
||||
lbry.setDaemonSetting('max_download', Number(event.target.value));
|
||||
},
|
||||
getInitialState: function() {
|
||||
return {
|
||||
settings: null
|
||||
settings: null,
|
||||
showNsfw: lbry.getClientSetting('showNsfw')
|
||||
}
|
||||
},
|
||||
componentDidMount: function() {
|
||||
document.title = "Settings";
|
||||
},
|
||||
componentWillMount: function() {
|
||||
lbry.getSettings(function(settings) {
|
||||
lbry.getDaemonSettings(function(settings) {
|
||||
this.setState({
|
||||
settings: settings,
|
||||
daemonSettings: settings,
|
||||
isMaxUpload: settings.max_upload != 0,
|
||||
isMaxDownload: settings.max_download != 0
|
||||
});
|
||||
}.bind(this));
|
||||
},
|
||||
onShowNsfwChange: function(event) {
|
||||
lbry.setClientSetting('showNsfw', event.target.checked);
|
||||
},
|
||||
render: function() {
|
||||
if (!this.state.settings) { // If the settings aren't loaded yet, don't render anything.
|
||||
if (!this.state.daemonSettings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<section className="card">
|
||||
<h3>Content Filtering</h3>
|
||||
<label style={settingsCheckBoxOptionStyles}>
|
||||
<input type="checkbox" onChange={this.onRunOnNsfwChange} defaultChecked={this.state.settings.show_nsfw} /> Show NSFW content
|
||||
</label>
|
||||
</section>
|
||||
<section className="card">
|
||||
<h3>Run on Startup</h3>
|
||||
<label style={settingsCheckBoxOptionStyles}>
|
||||
<input type="checkbox" onChange={this.onRunOnStartChange} defaultChecked={this.state.settings.run_on_startup} /> Run LBRY automatically when I start my computer
|
||||
<input type="checkbox" onChange={this.onRunOnStartChange} defaultChecked={this.state.daemonSettings.run_on_startup} /> Run LBRY automatically when I start my computer
|
||||
</label>
|
||||
</section>
|
||||
<section className="card">
|
||||
<h3>Download Directory</h3>
|
||||
<div className="help">Where would you like the files you download from LBRY to be saved?</div>
|
||||
<input style={downloadDirectoryFieldStyles} type="text" name="download_directory" defaultValue={this.state.settings.download_directory} onChange={this.onDownloadDirChange}/>
|
||||
<input style={downloadDirectoryFieldStyles} type="text" name="download_directory" defaultValue={this.state.daemonSettings.download_directory} onChange={this.onDownloadDirChange}/>
|
||||
</section>
|
||||
<section className="card">
|
||||
<h3>Bandwidth Limits</h3>
|
||||
|
@ -106,7 +93,7 @@ var SettingsPage = React.createClass({
|
|||
</label>
|
||||
<label style={settingsRadioOptionStyles}>
|
||||
<input type="radio" name="max_upload_pref" onChange={this.onMaxUploadPrefChange.bind(this, true)} defaultChecked={this.state.isMaxUpload}/> { this.state.isMaxUpload ? 'Up to' : 'Choose limit...' }
|
||||
<span className={ this.state.isMaxUpload ? '' : 'hidden'}> <input type="number" min="0" step=".5" defaultValue={this.state.settings.max_upload} style={settingsNumberFieldStyles} onChange={this.onMaxUploadFieldChange}/> MB/s</span>
|
||||
<span className={ this.state.isMaxUpload ? '' : 'hidden'}> <input type="number" min="0" step=".5" defaultValue={this.state.daemonSettings.max_upload} style={settingsNumberFieldStyles} onChange={this.onMaxUploadFieldChange}/> MB/s</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
|
@ -116,14 +103,20 @@ var SettingsPage = React.createClass({
|
|||
</label>
|
||||
<label style={settingsRadioOptionStyles}>
|
||||
<input type="radio" name="max_download_pref" onChange={this.onMaxDownloadPrefChange.bind(this, true)} defaultChecked={this.state.isMaxDownload}/> { this.state.isMaxDownload ? 'Up to' : 'Choose limit...' }
|
||||
<span className={ this.state.isMaxDownload ? '' : 'hidden'}> <input type="number" min="0" step=".5" defaultValue={this.state.settings.max_download} style={settingsNumberFieldStyles} onChange={this.onMaxDownloadFieldChange}/> MB/s</span>
|
||||
<span className={ this.state.isMaxDownload ? '' : 'hidden'}> <input type="number" min="0" step=".5" defaultValue={this.state.daemonSettings.max_download} style={settingsNumberFieldStyles} onChange={this.onMaxDownloadFieldChange}/> MB/s</span>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
<section className="card">
|
||||
<h3>Content</h3>
|
||||
<label style={settingsCheckBoxOptionStyles}>
|
||||
<input type="checkbox" onChange={this.onShowNsfwChange} defaultChecked={this.state.showNsfw} /> Include Not Safe For Work content in search results and Commmunity Content
|
||||
</label>
|
||||
</section>
|
||||
<section className="card">
|
||||
<h3>Share Diagnostic Data</h3>
|
||||
<label style={settingsCheckBoxOptionStyles}>
|
||||
<input type="checkbox" onChange={this.onShareDataChange} defaultChecked={this.state.settings.upload_log} /> Help make LBRY better by contributing diagnostic data about my usage
|
||||
<input type="checkbox" onChange={this.onShareDataChange} defaultChecked={this.state.daemonSettings.upload_log} /> Help make LBRY better by contributing diagnostic data about my usage
|
||||
</label>
|
||||
</section>
|
||||
</main>
|
||||
|
|
Loading…
Reference in a new issue