import React from 'react'; import {FormField, FormRow} from '../component/form.js'; import {SubHeader} from '../component/sub-header.js'; import lbry from '../lbry.js'; export let SettingsNav = React.createClass({ render: function() { return ; } }); var SettingsPage = React.createClass({ _onSettingSaveSuccess: function() { // This is bad. // document.dispatchEvent(new CustomEvent('globalNotice', { // detail: { // message: "Settings saved", // }, // })) }, setDaemonSetting: function(name, value) { lbry.setDaemonSetting(name, value, this._onSettingSaveSuccess) }, setClientSetting: function(name, value) { lbry.setClientSetting(name, value) this._onSettingSaveSuccess() }, onRunOnStartChange: function (event) { this.setDaemonSetting('run_on_startup', event.target.checked); }, onShareDataChange: function (event) { this.setDaemonSetting('share_usage_data', event.target.checked); }, onDownloadDirChange: function(event) { this.setDaemonSetting('download_directory', event.target.value); }, onMaxUploadPrefChange: function(isLimited) { if (!isLimited) { this.setDaemonSetting('max_upload', 0.0); } this.setState({ isMaxUpload: isLimited }); }, onMaxUploadFieldChange: function(event) { this.setDaemonSetting('max_upload', Number(event.target.value)); }, onMaxDownloadPrefChange: function(isLimited) { if (!isLimited) { this.setDaemonSetting('max_download', 0.0); } this.setState({ isMaxDownload: isLimited }); }, onMaxDownloadFieldChange: function(event) { this.setDaemonSetting('max_download', Number(event.target.value)); }, getInitialState: function() { return { settings: null, showNsfw: lbry.getClientSetting('showNsfw'), showUnavailable: lbry.getClientSetting('showUnavailable'), } }, componentWillMount: function() { lbry.getDaemonSettings((settings) => { this.setState({ daemonSettings: settings, isMaxUpload: settings.max_upload != 0, isMaxDownload: settings.max_download != 0 }); }); }, onShowNsfwChange: function(event) { lbry.setClientSetting('showNsfw', event.target.checked); }, onShowUnavailableChange: function(event) { }, render: function() { if (!this.state.daemonSettings) { return null; } /*

Run on Startup

*/ return (

Download Directory

Bandwidth Limits

Max Upload
{ this.onMaxUploadPrefChange(false) }} defaultChecked={!this.state.isMaxUpload} label="Unlimited" />
{ this.onMaxUploadPrefChange(true) }} defaultChecked={this.state.isMaxUpload} label={ this.state.isMaxUpload ? 'Up to' : 'Choose limit...' } /> { this.state.isMaxUpload ? : '' } { this.state.isMaxUpload ? MB/s : '' }
Max Download
{ this.onMaxDownloadPrefChange(false) }} defaultChecked={!this.state.isMaxDownload} />
{ this.onMaxDownloadPrefChange(true) }} defaultChecked={this.state.isMaxDownload} label={ this.state.isMaxDownload ? 'Up to' : 'Choose limit...' } /> { this.state.isMaxDownload ? : '' } { this.state.isMaxDownload ? MB/s : '' }

Content

Share Diagnostic Data

); } }); export default SettingsPage;