lbry-desktop/src/renderer/page/settings/view.jsx

345 lines
10 KiB
React
Raw Normal View History

import React from 'react';
import FormField from 'component/formField';
import { FormRow } from 'component/form.js';
import SubHeader from 'component/subHeader';
import * as settings from 'constants/settings';
import lbry from 'lbry.js';
import Link from 'component/link';
import FormFieldPrice from 'component/formFieldPrice';
2017-06-08 06:42:19 +02:00
class SettingsPage extends React.PureComponent {
2017-05-17 10:10:25 +02:00
constructor(props) {
super(props);
this.state = {
clearingCache: false,
2017-06-06 23:19:12 +02:00
};
2017-05-17 10:10:25 +02:00
}
clearCache() {
this.setState({
clearingCache: true,
});
const success = () => {
this.setState({ clearingCache: false });
window.location.href = 'index.html';
};
const clear = () => this.props.clearCache().then(success.bind(this));
setTimeout(clear, 1000, { once: true });
}
2017-05-17 10:10:25 +02:00
setDaemonSetting(name, value) {
2017-06-06 23:19:12 +02:00
this.props.setDaemonSetting(name, value);
2017-05-17 10:10:25 +02:00
}
onRunOnStartChange(event) {
this.setDaemonSetting('run_on_startup', event.target.checked);
2017-05-17 10:10:25 +02:00
}
onShareDataChange(event) {
this.setDaemonSetting('share_usage_data', event.target.checked);
2017-05-17 10:10:25 +02:00
}
onDownloadDirChange(event) {
this.setDaemonSetting('download_directory', event.target.value);
2017-05-17 10:10:25 +02:00
}
onKeyFeeChange(newValue) {
const setting = newValue;
// this is stupid and should be fixed... somewhere
if (setting && (setting.amount === undefined || setting.amount === null)) {
setting.amount = 0;
}
this.setDaemonSetting('max_key_fee', setting);
2017-05-17 10:10:25 +02:00
}
onKeyFeeDisableChange(isDisabled) {
this.setDaemonSetting('disable_max_key_fee', isDisabled);
2017-05-17 10:10:25 +02:00
}
2017-08-05 03:36:36 +02:00
onThemeChange(event) {
const { value } = event.target;
2017-09-07 02:52:34 +02:00
this.props.setClientSetting(settings.THEME, value);
2017-08-05 03:36:36 +02:00
}
onInstantPurchaseEnabledChange(enabled) {
this.props.setClientSetting(settings.INSTANT_PURCHASE_ENABLED, enabled);
}
onInstantPurchaseMaxChange(newValue) {
this.props.setClientSetting(settings.INSTANT_PURCHASE_MAX, newValue);
}
2017-07-25 00:15:51 +02:00
// 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));
// }
2017-05-17 10:10:25 +02:00
onShowNsfwChange(event) {
this.props.setClientSetting(settings.SHOW_NSFW, event.target.checked);
2017-05-17 10:10:25 +02:00
}
2017-07-07 15:15:45 +02:00
onLanguageChange(e) {
2017-07-07 15:26:03 +02:00
this.props.changeLanguage(e.target.value);
2017-08-23 01:50:59 +02:00
this.forceUpdate();
}
2017-09-07 03:53:42 +02:00
onShowUnavailableChange(event) {
this.props.setClientSetting(settings.SHOW_UNAVAILABLE, event.target.checked);
2017-09-07 03:53:42 +02:00
}
2017-04-12 16:55:19 +02:00
componentWillMount() {
2017-09-07 02:52:34 +02:00
this.props.getThemes();
}
2017-08-20 01:59:48 +02:00
componentDidMount() {}
2017-08-07 05:01:10 +02:00
2017-05-17 10:10:25 +02:00
render() {
2017-09-07 03:53:42 +02:00
const {
daemonSettings,
language,
languages,
showNsfw,
instantPurchaseEnabled,
instantPurchaseMax,
2017-09-07 03:53:42 +02:00
showUnavailable,
theme,
themes,
} = this.props;
if (!daemonSettings || Object.keys(daemonSettings).length === 0) {
2017-06-06 23:19:12 +02:00
return (
<main className="main--single-column">
<span className="empty">{__('Failed to load settings.')}</span>
2017-06-06 23:19:12 +02:00
</main>
);
2016-04-10 02:00:56 +02:00
}
return (
<main className="main--single-column">
2017-05-05 07:48:15 +02:00
<SubHeader />
{/*
<section className="card">
<div className="card__content">
2017-10-15 03:56:51 +02:00
<h4>{__("Language")}</h4>
</div>
<div className="card__content">
<div className="form-row">
<FormField
2017-08-19 20:03:51 +02:00
type="select"
name="language"
2017-08-24 19:33:41 +02:00
defaultValue={language}
2017-07-07 15:37:24 +02:00
onChange={this.onLanguageChange.bind(this)}
2017-08-19 20:03:51 +02:00
>
<option value="en">{__("English")}</option>
{Object.keys(languages).map(dLang =>
2017-08-24 19:33:41 +02:00
<option key={dLang} value={dLang}>
2017-08-19 20:03:51 +02:00
{languages[dLang]}
</option>
)}
</FormField>
</div>
</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">
<h4>{__('Download Directory')}</h4>
2017-04-10 14:32:40 +02:00
</div>
<div className="card__content">
2017-06-06 23:19:12 +02:00
<FormRow
type="directory"
name="download_directory"
defaultValue={daemonSettings.download_directory}
helper={__('LBRY downloads will be saved here.')}
2017-06-06 23:19:12 +02:00
onChange={this.onDownloadDirChange.bind(this)}
/>
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">
<h4>{__('Max Purchase Price')}</h4>
2017-04-10 14:32:40 +02:00
</div>
<div className="card__content">
2017-06-06 23:19:12 +02:00
<FormRow
type="radio"
name="max_key_fee"
onClick={() => {
this.onKeyFeeDisableChange(true);
2017-06-06 23:19:12 +02:00
}}
defaultChecked={daemonSettings.disable_max_key_fee}
label={__('No Limit')}
2017-06-06 23:19:12 +02:00
/>
2017-04-12 16:55:19 +02:00
<div className="form-row">
2017-06-06 23:19:12 +02:00
<FormField
type="radio"
name="max_key_fee"
onClick={() => {
this.onKeyFeeDisableChange(false);
2017-06-06 23:19:12 +02:00
}}
defaultChecked={!daemonSettings.disable_max_key_fee}
label={daemonSettings.disable_max_key_fee ? __('Choose limit') : __('Limit to')}
2017-06-06 23:19:12 +02:00
/>
2017-11-24 15:31:05 +01:00
{!daemonSettings.disable_max_key_fee && (
<FormFieldPrice
min="0"
onChange={this.onKeyFeeChange.bind(this)}
defaultValue={
daemonSettings.max_key_fee
? daemonSettings.max_key_fee
: { currency: 'USD', amount: 50 }
}
2017-11-24 15:31:05 +01:00
/>
)}
2017-04-12 16:55:19 +02:00
</div>
<div className="form-field__helper">
{__(
'This will prevent you from purchasing any content over this cost, as a safety measure.'
)}
2017-04-12 16:55:19 +02:00
</div>
2016-08-08 05:31:21 +02:00
</div>
2017-10-15 02:42:21 +02:00
</section>
<section className="card">
<div className="card__content">
<h4>{__('Purchase Confirmations')}</h4>
2017-10-15 02:42:21 +02:00
</div>
<div className="card__content">
2017-09-23 00:31:23 +02:00
<FormRow
type="radio"
name="instant_purchase_max"
2017-10-27 23:14:42 +02:00
defaultChecked={!instantPurchaseEnabled}
label={__('Ask for confirmation of all purchases')}
onClick={e => {
this.onInstantPurchaseEnabledChange(false);
}}
/>
<div className="form-row">
<FormField
type="radio"
name="instant_purchase_max"
2017-10-27 23:14:42 +02:00
defaultChecked={instantPurchaseEnabled}
label={`Single-click purchasing of content less than${
instantPurchaseEnabled ? '' : '...'
}`}
onClick={e => {
this.onInstantPurchaseEnabledChange(true);
}}
/>
2017-11-24 15:31:05 +01:00
{instantPurchaseEnabled && (
<FormFieldPrice
min="0.1"
onChange={val => this.onInstantPurchaseMaxChange(val)}
defaultValue={instantPurchaseMax}
2017-11-24 15:31:05 +01:00
/>
)}
</div>
<div className="form-field__helper">
When this option is chosen, LBRY won't ask you to confirm downloads below the given
price.
</div>
</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">
<h4>{__('Content')}</h4>
</div>
2017-04-10 20:12:07 +02:00
<div className="card__content">
2017-06-06 23:19:12 +02:00
<FormRow
type="checkbox"
onChange={this.onShowUnavailableChange.bind(this)}
2017-09-07 03:53:42 +02:00
defaultChecked={showUnavailable}
label={__('Show unavailable content in search results')}
2017-06-06 23:19:12 +02:00
/>
<FormRow
label={__('Show NSFW content')}
2017-06-06 23:19:12 +02:00
type="checkbox"
onChange={this.onShowNsfwChange.bind(this)}
2017-09-07 03:53:42 +02:00
defaultChecked={showNsfw}
2017-06-06 23:19:12 +02:00
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. '
2017-06-06 23:19:12 +02:00
)}
/>
</div>
</section>
2017-06-06 06:21:55 +02:00
2016-08-08 00:45:26 +02:00
<section className="card">
2017-04-10 14:32:40 +02:00
<div className="card__content">
<h4>{__('Share Diagnostic Data')}</h4>
2017-04-10 14:32:40 +02:00
</div>
2017-04-10 20:12:07 +02:00
<div className="card__content">
2017-06-06 23:19:12 +02:00
<FormRow
type="checkbox"
onChange={this.onShareDataChange.bind(this)}
defaultChecked={daemonSettings.share_usage_data}
label={__('Help make LBRY better by contributing diagnostic data about my usage')}
2017-06-06 23:19:12 +02:00
/>
2017-04-10 14:32:40 +02:00
</div>
2016-04-10 02:00:56 +02:00
</section>
2017-08-05 03:36:36 +02:00
<section className="card">
<div className="card__content">
<h4>{__('Theme')}</h4>
2017-08-05 03:36:36 +02:00
</div>
<div className="card__content">
<FormField
type="select"
onChange={this.onThemeChange.bind(this)}
2017-09-07 03:53:42 +02:00
defaultValue={theme}
2017-08-05 03:36:36 +02:00
className="form-field__input--inline"
>
2017-11-24 15:31:05 +01:00
{themes.map((theme, index) => (
2017-09-07 02:52:34 +02:00
<option key={theme} value={theme}>
{theme}
</option>
2017-11-24 15:31:05 +01:00
))}
2017-08-05 03:36:36 +02:00
</FormField>
</div>
</section>
<section className="card">
<div className="card__content">
<h4>{__('Application Cache')}</h4>
</div>
<div className="card__content">
<p>
<Link
label={this.state.clearingCache ? __('Clearing') : __('Clear the cache')}
icon="icon-trash"
button="alt"
onClick={this.clearCache.bind(this)}
disabled={this.state.clearingCache}
/>
</p>
</div>
</section>
2017-06-06 23:19:12 +02:00
</main>
2016-04-10 02:00:56 +02:00
);
}
2017-05-17 10:10:25 +02:00
}
2016-11-22 21:19:08 +01:00
export default SettingsPage;