lbry-desktop/ui/js/page/settings.js

182 lines
7 KiB
JavaScript
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
2017-04-10 14:32:40 +02:00
import {FormField, FormRow} from '../component/form.js';
2016-11-22 21:19:08 +01:00
import lbry from '../lbry.js';
2016-04-10 02:00:56 +02:00
var SettingsPage = React.createClass({
onRunOnStartChange: function (event) {
lbry.setDaemonSetting('run_on_startup', event.target.checked);
2016-04-10 02:00:56 +02:00
},
onShareDataChange: function (event) {
2017-03-29 17:07:29 +02:00
lbry.setDaemonSetting('share_debug_info', event.target.checked);
2016-04-10 02:00:56 +02:00
},
onDownloadDirChange: function(event) {
lbry.setDaemonSetting('download_directory', event.target.value);
2016-04-10 02:00:56 +02:00
},
onMaxUploadPrefChange: function(isLimited) {
if (!isLimited) {
lbry.setDaemonSetting('max_upload', 0.0);
2016-04-10 02:00:56 +02:00
}
this.setState({
isMaxUpload: isLimited
});
},
onMaxUploadFieldChange: function(event) {
lbry.setDaemonSetting('max_upload', Number(event.target.value));
2016-04-10 02:00:56 +02:00
},
onMaxDownloadPrefChange: function(isLimited) {
if (!isLimited) {
lbry.setDaemonSetting('max_download', 0.0);
2016-04-10 02:00:56 +02:00
}
this.setState({
isMaxDownload: isLimited
});
},
onMaxDownloadFieldChange: function(event) {
lbry.setDaemonSetting('max_download', Number(event.target.value));
2016-04-10 02:00:56 +02:00
},
getInitialState: function() {
return {
settings: null,
showNsfw: lbry.getClientSetting('showNsfw'),
showUnavailable: lbry.getClientSetting('showUnavailable'),
2016-04-10 02:00:56 +02:00
}
},
2016-08-07 23:05:04 +02:00
componentDidMount: function() {
document.title = "Settings";
},
2016-04-10 02:00:56 +02:00
componentWillMount: function() {
lbry.getDaemonSettings(function(settings) {
2016-04-10 02:00:56 +02:00
this.setState({
daemonSettings: settings,
2016-04-10 02:00:56 +02:00
isMaxUpload: settings.max_upload != 0,
isMaxDownload: settings.max_download != 0
});
}.bind(this));
},
2016-08-22 21:19:04 +02:00
onShowNsfwChange: function(event) {
lbry.setClientSetting('showNsfw', event.target.checked);
},
onShowUnavailableChange: function(event) {
lbry.setClientSetting('showUnavailable', event.target.checked);
},
2016-04-10 02:00:56 +02:00
render: function() {
if (!this.state.daemonSettings) {
2016-04-10 02:00:56 +02:00
return null;
}
return (
2016-08-08 00:45:26 +02:00
<main>
<section className="card">
2017-04-10 14:32:40 +02:00
<div className="card__content">
<h3>Run on Startup</h3>
</div>
<div className="card__content">
<FormRow type="checkbox"
onChange={this.onRunOnStartChange}
defaultChecked={this.state.daemonSettings.run_on_startup}
label="Run LBRY automatically when I start my computer" />
</div>
2016-04-10 02:00:56 +02:00
</section>
2016-08-08 00:45:26 +02:00
<section className="card">
2017-04-10 14:32:40 +02:00
<div className="card__content">
<h3>Download Directory</h3>
</div>
<div className="card__content">
<FormRow type="text"
name="download_directory"
defaultValue={this.state.daemonSettings.download_directory}
helper="LBRY downloads will be saved here."
onChange={this.onDownloadDirChange} />
</div>
2016-04-10 02:00:56 +02:00
</section>
2016-08-08 00:45:26 +02:00
<section className="card">
2017-04-10 14:32:40 +02:00
<div className="card__content">
<h3>Bandwidth Limits</h3>
</div>
<div className="card__content">
2016-08-08 05:31:21 +02:00
<h4>Max Upload</h4>
2017-04-10 14:32:40 +02:00
<FormField type="radio"
name="max_upload_pref"
onChange={this.onMaxUploadPrefChange.bind(this, false)}
defaultChecked={!this.state.isMaxUpload}
label="Unlimited" />
<FormField type="radio"
name="max_upload_pref"
onChange={this.onMaxUploadPrefChange.bind(this, true)}
defaultChecked={this.state.isMaxUpload}
label={ this.state.isMaxUpload ? 'Up to' : 'Choose limit...' } />
{ this.state.isMaxUpload ?
<FormField type="number"
min="0"
step=".5"
label="MB/s"
onChange={this.onMaxUploadFieldChange}
/> : ''
}
2016-08-08 05:31:21 +02:00
</div>
2017-04-10 14:32:40 +02:00
<div className="card__content">
2016-08-08 05:31:21 +02:00
<h4>Max Download</h4>
<label style={settingsRadioOptionStyles}>
<input type="radio" name="max_download_pref" onChange={this.onMaxDownloadPrefChange.bind(this, false)} defaultChecked={!this.state.isMaxDownload}/> Unlimited
</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.daemonSettings.max_download} style={settingsNumberFieldStyles} onChange={this.onMaxDownloadFieldChange}/> MB/s</span>
2016-08-08 05:31:21 +02:00
</label>
</div>
2016-04-10 02:00:56 +02:00
</section>
2016-08-22 21:19:04 +02:00
<section className="card">
2017-04-10 14:32:40 +02:00
<div className="card__content">
<h3>Content</h3>
</div>
2017-04-10 14:32:40 +02:00
<div class="card__content">
<FormRow type="checkbox"
onChange={this.onShowUnavailableChange}
defaultChecked={this.state.showUnavailable}
label="Show unavailable content in search results" />
</div>
2017-04-10 14:32:40 +02:00
<div className="card__content">
<FormRow label="Show NSFW content" type="checkbox"
onChange={this.onShowNsfwChange} defaultChecked={this.state.showNsfw}
helper="NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. " />
</div>
</section>
2016-08-08 00:45:26 +02:00
<section className="card">
2017-04-10 14:32:40 +02:00
<div className="card__content">
<h3>Share Diagnostic Data</h3>
</div>
<div class="card__content">
<FormRow type="checkbox"
onChange={this.onShareDataChange}
defaultChecked={this.state.daemonSettings.share_debug_info}
label="Help make LBRY better by contributing diagnostic data about my usage" />
</div>
2016-04-10 02:00:56 +02:00
</section>
</main>
);
}
2016-08-21 22:59:32 +02:00
});
2016-11-22 21:19:08 +01:00
2017-04-10 14:32:40 +02:00
/*
<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">
<h3>Share Diagnostic Data</h3>
<label style={settingsCheckBoxOptionStyles}>
<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>
*/
2016-11-22 21:19:08 +01:00
export default SettingsPage;