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

191 lines
7.2 KiB
React
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import {FormField, FormRow} from 'component/form.js';
2017-05-05 07:48:15 +02:00
import SubHeader from 'component/subHeader'
import lbry from 'lbry.js';
2016-11-22 21:19:08 +01:00
2016-04-10 02:00:56 +02:00
var SettingsPage = React.createClass({
2017-04-12 16:55:19 +02:00
setDaemonSetting: function(name, value) {
this.props.setDaemonSetting(name, value)
2017-04-12 16:55:19 +02:00
},
setClientSetting: function(name, value) {
lbry.setClientSetting(name, value)
this._onSettingSaveSuccess()
},
2016-04-10 02:00:56 +02:00
onRunOnStartChange: function (event) {
2017-04-12 16:55:19 +02:00
this.setDaemonSetting('run_on_startup', event.target.checked);
2016-04-10 02:00:56 +02:00
},
onShareDataChange: function (event) {
2017-05-03 19:56:39 +02:00
this.setDaemonSetting('share_usage_data', event.target.checked);
2016-04-10 02:00:56 +02:00
},
onDownloadDirChange: function(event) {
2017-04-12 16:55:19 +02:00
this.setDaemonSetting('download_directory', event.target.value);
2016-04-10 02:00:56 +02:00
},
onMaxUploadPrefChange: function(isLimited) {
if (!isLimited) {
2017-04-12 16:55:19 +02:00
this.setDaemonSetting('max_upload', 0.0);
2016-04-10 02:00:56 +02:00
}
this.setState({
isMaxUpload: isLimited
});
},
onMaxUploadFieldChange: function(event) {
2017-04-12 16:55:19 +02:00
this.setDaemonSetting('max_upload', Number(event.target.value));
2016-04-10 02:00:56 +02:00
},
onMaxDownloadPrefChange: function(isLimited) {
if (!isLimited) {
2017-04-12 16:55:19 +02:00
this.setDaemonSetting('max_download', 0.0);
2016-04-10 02:00:56 +02:00
}
this.setState({
isMaxDownload: isLimited
});
},
onMaxDownloadFieldChange: function(event) {
2017-04-12 16:55:19 +02:00
this.setDaemonSetting('max_download', Number(event.target.value));
2016-04-10 02:00:56 +02:00
},
getInitialState: function() {
const daemonSettings = this.props.daemonSettings
2016-04-10 02:00:56 +02:00
return {
isMaxUpload: daemonSettings && daemonSettings.max_upload != 0,
isMaxDownload: daemonSettings && daemonSettings.max_download != 0,
showNsfw: lbry.getClientSetting('showNsfw'),
showUnavailable: lbry.getClientSetting('showUnavailable'),
2016-04-10 02:00:56 +02:00
}
},
2016-08-22 21:19:04 +02:00
onShowNsfwChange: function(event) {
lbry.setClientSetting('showNsfw', event.target.checked);
},
onShowUnavailableChange: function(event) {
2017-04-12 16:55:19 +02:00
},
2016-04-10 02:00:56 +02:00
render: function() {
const {
daemonSettings
} = this.props
if (!daemonSettings) {
return <main className="main--single-column"><span className="empty">Failed to load settings.</span></main>;
2016-04-10 02:00:56 +02:00
}
2017-04-12 22:23:20 +02:00
/*
<section className="card">
<div className="card__content">
<h3>Run on Startup</h3>
</div>
<div className="card__content">
<FormRow type="checkbox"
onChange={this.onRunOnStartChange}
defaultChecked={daemonSettings.run_on_startup}
2017-04-12 22:23:20 +02:00
label="Run LBRY automatically when I start my computer" />
</div>
</section>
*/
2016-04-10 02:00:56 +02:00
return (
<main className="main--single-column">
2017-05-05 07:48:15 +02:00
<SubHeader />
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="directory"
name="download_directory"
defaultValue={daemonSettings.download_directory}
helper="LBRY downloads will be saved here."
onChange={this.onDownloadDirChange} />
2017-04-10 14:32:40 +02:00
</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">
2017-04-12 16:55:19 +02:00
<div className="form-row__label-row"><div className="form-field__label">Max Upload</div></div>
2017-04-10 20:12:07 +02:00
<FormRow type="radio"
2017-04-10 14:32:40 +02:00
name="max_upload_pref"
onChange={() => { this.onMaxUploadPrefChange(false) }}
2017-04-10 14:32:40 +02:00
defaultChecked={!this.state.isMaxUpload}
label="Unlimited" />
2017-04-12 16:55:19 +02:00
<div className="form-row">
<FormField type="radio"
name="max_upload_pref"
onChange={() => { this.onMaxUploadPrefChange(true) }}
2017-04-12 16:55:19 +02:00
defaultChecked={this.state.isMaxUpload}
label={ this.state.isMaxUpload ? 'Up to' : 'Choose limit...' } />
{ this.state.isMaxUpload ?
<FormField type="number"
min="0"
step=".5"
defaultValue={daemonSettings.max_upload}
2017-04-12 16:55:19 +02:00
placeholder="10"
className="form-field__input--inline"
onChange={this.onMaxUploadFieldChange}
/>
: ''
}
{ this.state.isMaxUpload ? <span className="form-field__label">MB/s</span> : '' }
</div>
2016-08-08 05:31:21 +02:00
</div>
2017-04-10 14:32:40 +02:00
<div className="card__content">
2017-04-12 16:55:19 +02:00
<div className="form-row__label-row"><div className="form-field__label">Max Download</div></div>
<FormRow label="Unlimited"
2017-04-10 20:12:07 +02:00
type="radio"
name="max_download_pref"
onChange={() => { this.onMaxDownloadPrefChange(false) }}
2017-04-10 20:12:07 +02:00
defaultChecked={!this.state.isMaxDownload} />
2017-04-12 16:55:19 +02:00
<div className="form-row">
<FormField type="radio"
name="max_download_pref"
onChange={() => { this.onMaxDownloadPrefChange(true) }}
2017-04-12 16:55:19 +02:00
defaultChecked={this.state.isMaxDownload}
label={ this.state.isMaxDownload ? 'Up to' : 'Choose limit...' } />
{ this.state.isMaxDownload ?
<FormField type="number"
min="0"
step=".5"
defaultValue={daemonSettings.max_download}
2017-04-12 16:55:19 +02:00
placeholder="10"
className="form-field__input--inline"
onChange={this.onMaxDownloadFieldChange}
/>
: ''
}
{ this.state.isMaxDownload ? <span className="form-field__label">MB/s</span> : '' }
</div>
2016-08-08 05:31:21 +02:00
</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 20:12:07 +02:00
<div className="card__content">
2017-04-10 14:32:40 +02:00
<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>
2017-04-10 20:12:07 +02:00
<div className="card__content">
2017-04-10 14:32:40 +02:00
<FormRow type="checkbox"
onChange={this.onShareDataChange}
defaultChecked={daemonSettings.share_usage_data}
2017-04-10 14:32:40 +02:00
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
export default SettingsPage;