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

324 lines
11 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as React from 'react';
import { FormField, FormFieldPrice } from 'component/common/form';
import * as settings from 'constants/settings';
2018-03-26 23:32:43 +02:00
import * as icons from 'constants/icons';
import Button from 'component/button';
import Page from 'component/page';
import FileSelector from 'component/common/file-selector';
export type Price = {
currency: string,
amount: number,
};
type DaemonSettings = {
download_directory: string,
disable_max_key_fee: boolean,
share_usage_data: boolean,
};
type Props = {
setDaemonSetting: (string, boolean | string | Price) => void,
setClientSetting: (string, boolean | string | number | Price) => void,
2018-03-26 23:32:43 +02:00
clearCache: () => Promise<any>,
getThemes: () => void,
daemonSettings: DaemonSettings,
showNsfw: boolean,
instantPurchaseEnabled: boolean,
instantPurchaseMax: Price,
currentTheme: string,
themes: Array<string>,
automaticDarkModeEnabled: boolean,
2018-05-30 05:18:41 +02:00
autoplay: boolean,
2018-03-26 23:32:43 +02:00
};
type State = {
clearingCache: boolean,
};
class SettingsPage extends React.PureComponent<Props, State> {
constructor(props: Props) {
2017-05-17 10:10:25 +02:00
super(props);
this.state = {
clearingCache: false,
2017-06-06 23:19:12 +02:00
};
2018-03-26 23:32:43 +02:00
(this: any).onDownloadDirChange = this.onDownloadDirChange.bind(this);
(this: any).onKeyFeeChange = this.onKeyFeeChange.bind(this);
(this: any).onInstantPurchaseMaxChange = this.onInstantPurchaseMaxChange.bind(this);
(this: any).onShowNsfwChange = this.onShowNsfwChange.bind(this);
(this: any).onShareDataChange = this.onShareDataChange.bind(this);
(this: any).onThemeChange = this.onThemeChange.bind(this);
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
(this: any).onAutoplayChange = this.onAutoplayChange.bind(this);
2018-03-26 23:32:43 +02:00
(this: any).clearCache = this.clearCache.bind(this);
// (this: any).onLanguageChange = this.onLanguageChange.bind(this)
}
2018-03-26 23:32:43 +02:00
componentDidMount() {
this.props.getThemes();
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onRunOnStartChange(event: SyntheticInputEvent<*>) {
this.setDaemonSetting('run_on_startup', event.target.checked);
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onShareDataChange(event: SyntheticInputEvent<*>) {
this.setDaemonSetting('share_usage_data', event.target.checked);
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onDownloadDirChange(newDirectory: string) {
this.setDaemonSetting('download_directory', newDirectory);
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onKeyFeeChange(newValue: Price) {
this.setDaemonSetting('max_key_fee', newValue);
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onKeyFeeDisableChange(isDisabled: boolean) {
this.setDaemonSetting('disable_max_key_fee', isDisabled);
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onThemeChange(event: SyntheticInputEvent<*>) {
const { value } = event.target;
if (value === 'dark') {
this.onAutomaticDarkModeChange(false);
}
2017-09-07 02:52:34 +02:00
this.props.setClientSetting(settings.THEME, value);
2017-08-05 03:36:36 +02:00
}
2018-03-26 23:32:43 +02:00
onAutomaticDarkModeChange(value: boolean) {
this.props.setClientSetting(settings.AUTOMATIC_DARK_MODE_ENABLED, value);
2018-01-14 10:14:15 +01:00
}
onAutoplayChange(event: SyntheticInputEvent<*>) {
this.props.setClientSetting(settings.AUTOPLAY, event.target.checked);
}
2018-03-26 23:32:43 +02:00
onInstantPurchaseEnabledChange(enabled: boolean) {
this.props.setClientSetting(settings.INSTANT_PURCHASE_ENABLED, enabled);
}
2018-03-26 23:32:43 +02:00
onInstantPurchaseMaxChange(newValue: Price) {
this.props.setClientSetting(settings.INSTANT_PURCHASE_MAX, newValue);
}
2018-03-26 23:32:43 +02:00
onShowNsfwChange(event: SyntheticInputEvent<*>) {
this.props.setClientSetting(settings.SHOW_NSFW, event.target.checked);
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
setDaemonSetting(name: string, value: boolean | string | Price) {
this.props.setDaemonSetting(name, value);
}
2018-03-26 23:32:43 +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);
setTimeout(clear, 1000, { once: true });
}
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,
showNsfw,
instantPurchaseEnabled,
instantPurchaseMax,
2018-03-26 23:32:43 +02:00
currentTheme,
2017-09-07 03:53:42 +02:00
themes,
2018-01-14 10:14:15 +01:00
automaticDarkModeEnabled,
2018-05-30 05:18:41 +02:00
autoplay,
2017-09-07 03:53:42 +02:00
} = this.props;
2018-03-26 23:32:43 +02:00
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
const isDarkModeEnabled = currentTheme === 'dark';
2016-04-10 02:00:56 +02:00
return (
2018-03-26 23:32:43 +02:00
<Page>
{noDaemonSettings ? (
<section className="card card--section">
<div className="card__title">{__('Failed to load settings.')}</div>
</section>
) : (
<React.Fragment>
<section className="card card--section">
<div className="card__title">{__('Download Directory')}</div>
<span className="card__subtitle">{__('LBRY downloads will be saved here.')}</span>
<FileSelector
type="openDirectory"
currentPath={daemonSettings.download_directory}
onFileChosen={this.onDownloadDirChange}
2017-06-06 23:19:12 +02:00
/>
2018-03-26 23:32:43 +02:00
</section>
<section className="card card--section">
<div className="card__title">{__('Max Purchase Price')}</div>
<span className="card__subtitle">
{__(
'This will prevent you from purchasing any content over a certain cost, as a safety measure.'
)}
</span>
<div className="card__content">
<FormField
type="radio"
name="no_max_purchase_limit"
checked={daemonSettings.disable_max_key_fee}
postfix={__('No Limit')}
onChange={() => {
this.onKeyFeeDisableChange(true);
}}
/>
<FormField
type="radio"
name="max_purchase_limit"
onChange={() => {
this.onKeyFeeDisableChange(false);
}}
checked={!daemonSettings.disable_max_key_fee}
postfix={__('Choose limit')}
/>
2018-04-11 00:05:30 +02:00
{!daemonSettings.disable_max_key_fee && (
<FormFieldPrice
name="max_key_fee"
label="Max purchase price"
min={0}
onChange={this.onKeyFeeChange}
price={
daemonSettings.max_key_fee
? daemonSettings.max_key_fee
: { currency: 'USD', amount: 50 }
}
/>
)}
2018-03-26 23:32:43 +02:00
</div>
</section>
<section className="card card--section">
<div className="card__title">{__('Purchase Confirmations')}</div>
<div className="card__subtitle">
{__(
"When this option is chosen, LBRY won't ask you to confirm downloads below your chosen price."
)}
</div>
<div className="card__content">
<FormField
type="radio"
name="confirm_all_purchases"
checked={!instantPurchaseEnabled}
postfix={__('Always confirm before purchasing content')}
onChange={() => {
this.onInstantPurchaseEnabledChange(false);
}}
/>
<FormField
type="radio"
name="instant_purchases"
checked={instantPurchaseEnabled}
postfix={__('Only confirm purchases over a certain price')}
onChange={() => {
this.onInstantPurchaseEnabledChange(true);
}}
/>
2018-04-11 00:05:30 +02:00
{instantPurchaseEnabled && (
<FormFieldPrice
label={__('Confirmation price')}
min={0.1}
onChange={this.onInstantPurchaseMaxChange}
price={instantPurchaseMax}
/>
)}
2018-03-26 23:32:43 +02:00
</div>
</section>
<section className="card card--section">
<div className="card__title">{__('Content Settings')}</div>
<FormField
type="checkbox"
name="autoplay"
onChange={this.onAutoplayChange}
checked={autoplay}
postfix={__('Autoplay media files')}
/>
2018-03-26 23:32:43 +02:00
<FormField
type="checkbox"
name="show_nsfw"
onChange={this.onShowNsfwChange}
checked={showNsfw}
postfix={__('Show NSFW content')}
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. '
)}
/>
2018-03-26 23:32:43 +02:00
</section>
<section className="card card--section">
<div className="card__title">{__('Share Diagnostic Data')}</div>
2018-06-13 07:20:53 +02:00
<FormField
type="checkbox"
name="share_usage_data"
onChange={this.onShareDataChange}
checked={daemonSettings.share_usage_data}
postfix={__(
'Help make LBRY better by contributing analytics and diagnostic data about my usage.'
)}
helper={__(
'You will be ineligible to earn rewards while diagnostics are not being shared.'
)}
/>
2018-03-26 23:32:43 +02:00
</section>
{
2018-04-17 04:21:19 +02:00
<section className="card card--section">
<div className="card__title">{__('Theme')}</div>
<FormField
name="theme_select"
type="select"
onChange={this.onThemeChange}
value={currentTheme}
disabled={automaticDarkModeEnabled}
>
{themes.map(theme => (
<option key={theme} value={theme}>
{theme}
</option>
))}
</FormField>
<FormField
type="checkbox"
name="automatic_dark_mode"
onChange={e => this.onAutomaticDarkModeChange(e.target.checked)}
checked={automaticDarkModeEnabled}
disabled={isDarkModeEnabled}
2018-04-17 04:21:19 +02:00
postfix={__('Automatic dark mode (9pm to 8am)')}
/>
</section>
2018-03-26 23:32:43 +02:00
}
<section className="card card--section">
<div className="card__title">{__('Application Cache')}</div>
<span className="card__subtitle">
{__('This will clear the application cache. Your wallet will not be affected.')}
2018-03-26 23:32:43 +02:00
</span>
<div className="card__content">
<Button
button="primary"
label={this.state.clearingCache ? __('Clearing') : __('Clear the cache')}
icon={icons.ALERT}
onClick={this.clearCache}
disabled={this.state.clearingCache}
/>
</div>
</section>
</React.Fragment>
)}
</Page>
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;