import React from 'react'; import {FormField, FormRow} from 'component/form.js'; import SubHeader from 'component/subHeader' import lbry from 'lbry.js'; class SettingsPage extends React.Component { constructor(props) { super(props); const daemonSettings = this.props.daemonSettings this.state = { isMaxUpload: daemonSettings && daemonSettings.max_upload != 0, isMaxDownload: daemonSettings && daemonSettings.max_download != 0, showNsfw: lbry.getClientSetting('showNsfw'), showUnavailable: lbry.getClientSetting('showUnavailable'), language: lbry.getClientSetting('language'), } } setDaemonSetting(name, value) { this.props.setDaemonSetting(name, value) } setClientSetting(name, value) { lbry.setClientSetting(name, value) this._onSettingSaveSuccess() } onRunOnStartChange(event) { this.setDaemonSetting('run_on_startup', event.target.checked); } onShareDataChange(event) { this.setDaemonSetting('share_usage_data', event.target.checked); } onDownloadDirChange(event) { this.setDaemonSetting('download_directory', event.target.value); } onMaxUploadPrefChange(isLimited) { if (!isLimited) { this.setDaemonSetting('max_upload', 0.0); } this.setState({ isMaxUpload: isLimited }); } onMaxUploadFieldChange(event) { this.setDaemonSetting('max_upload', Number(event.target.value)); } onMaxDownloadPrefChange(isLimited) { if (!isLimited) { this.setDaemonSetting('max_download', 0.0); } this.setState({ isMaxDownload: isLimited }); } onMaxDownloadFieldChange(event) { this.setDaemonSetting('max_download', Number(event.target.value)); } onShowNsfwChange(event) { lbry.setClientSetting('showNsfw', event.target.checked); } // onLanguageChange(language) { // lbry.setClientSetting('language', language); // i18n.setLocale(language); // this.setState({language: language}) // } onShowUnavailableChange(event) { } render() { const { daemonSettings } = this.props if (!daemonSettings) { return {__("Failed to load settings.")}; } /* 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")} /* {__("Language")} { this.onLanguageChange('en') }} defaultChecked={this.state.language=='en'} /> { this.onLanguageChange('rs') }} defaultChecked={this.state.language=='rs'} /> */ {__("Share Diagnostic Data")} ); } } export default SettingsPage;