lbry-desktop/js/page/settings.js

126 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-04-10 02:00:56 +02:00
var settingsRadioOptionStyles = {
display: 'block',
marginLeft: '13px'
}, settingsCheckBoxOptionStyles = {
display: 'block',
marginLeft: '13px'
}, settingsNumberFieldStyles = {
width: '40px'
}, downloadDirectoryLabelStyles = {
fontSize: '.9em',
marginLeft: '13px'
}, downloadDirectoryFieldStyles= {
width: '300px'
};
var SettingsPage = React.createClass({
2016-08-22 21:19:04 +02:00
_initClientSettings: null,
2016-04-10 02:00:56 +02:00
onRunOnStartChange: function (event) {
lbry.setDaemonSetting('run_on_startup', event.target.checked);
2016-04-10 02:00:56 +02:00
},
onShareDataChange: function (event) {
lbry.setDaemonSetting('upload_log', 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
}
},
2016-08-07 23:05:04 +02:00
componentDidMount: function() {
document.title = "Settings";
2016-08-22 21:19:04 +02:00
this._initClientSettings = lbry.getClientSettings();
2016-08-07 23:05:04 +02:00
},
2016-04-10 02:00:56 +02:00
componentWillMount: function() {
lbry.getDaemonSettings(function(settings) {
2016-04-10 02:00:56 +02:00
this.setState({
initDaemonSettings: 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);
},
2016-04-10 02:00:56 +02:00
render: function() {
if (!this.state.initDaemonSettings) {
2016-04-10 02:00:56 +02:00
return null;
}
return (
2016-08-08 00:45:26 +02:00
<main>
<section className="card">
<h3>Run on Startup</h3>
2016-04-10 02:00:56 +02:00
<label style={settingsCheckBoxOptionStyles}>
<input type="checkbox" onChange={this.onRunOnStartChange} defaultChecked={this.state.initDaemonSettings.run_on_startup} /> Run LBRY automatically when I start my computer
2016-04-10 02:00:56 +02:00
</label>
</section>
2016-08-08 00:45:26 +02:00
<section className="card">
<h3>Download Directory</h3>
2016-04-10 02:00:56 +02:00
<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.initDaemonSettings.download_directory} onChange={this.onDownloadDirChange}/>
2016-04-10 02:00:56 +02:00
</section>
2016-08-08 00:45:26 +02:00
<section className="card">
<h3>Bandwidth Limits</h3>
2016-08-08 05:31:21 +02:00
<div className="form-row">
<h4>Max Upload</h4>
<label style={settingsRadioOptionStyles}>
<input type="radio" name="max_upload_pref" onChange={this.onMaxUploadPrefChange.bind(this, false)} defaultChecked={!this.state.isMaxUpload}/> Unlimited
</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.initDaemonSettings.max_upload} style={settingsNumberFieldStyles} onChange={this.onMaxUploadFieldChange}/> MB/s</span>
2016-08-08 05:31:21 +02:00
</label>
</div>
<div className="form-row">
<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.initDaemonSettings.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">
<h3>Content</h3>
<label style={settingsCheckBoxOptionStyles}>
<input type="checkbox" onChange={this.onShowNsfwChange} defaultChecked={this._initClientSettings.showNsfw} /> Include Not Safe For Work content in search results and Commmunity Content
</label>
</section>
2016-08-08 00:45:26 +02:00
<section className="card">
<h3>Share Diagnostic Data</h3>
2016-04-10 02:00:56 +02:00
<label style={settingsCheckBoxOptionStyles}>
<input type="checkbox" onChange={this.onShareDataChange} defaultChecked={this.state.initDaemonSettings.upload_log} /> Help make LBRY better by contributing diagnostic data about my usage
2016-04-10 02:00:56 +02:00
</label>
</section>
</main>
);
}
});