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

280 lines
8.5 KiB
React
Raw Normal View History

2017-06-06 23:19:12 +02:00
import React from "react";
import { FormField, FormRow } from "component/form.js";
import SubHeader from "component/subHeader";
import lbry from "lbry.js";
import Link from "component/link";
const { remote } = require("electron");
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);
const { daemonSettings } = this.props || {};
2017-05-17 10:10:25 +02:00
this.state = {
2017-07-25 00:15:51 +02:00
// isMaxUpload: daemonSettings && daemonSettings.max_upload != 0,
// isMaxDownload: daemonSettings && daemonSettings.max_download != 0,
2017-06-06 23:19:12 +02:00
showUnavailable: lbry.getClientSetting("showUnavailable"),
language: lbry.getClientSetting("language"),
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 = `${remote.app.getAppPath()}/dist/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
}
setClientSetting(name, value) {
2017-06-06 23:19:12 +02:00
lbry.setClientSetting(name, value);
this._onSettingSaveSuccess();
2017-05-17 10:10:25 +02:00
}
onRunOnStartChange(event) {
2017-06-06 23:19:12 +02:00
this.setDaemonSetting("run_on_startup", event.target.checked);
2017-05-17 10:10:25 +02:00
}
onShareDataChange(event) {
2017-06-06 23:19:12 +02:00
this.setDaemonSetting("share_usage_data", event.target.checked);
2017-05-17 10:10:25 +02:00
}
onDownloadDirChange(event) {
2017-06-06 23:19:12 +02:00
this.setDaemonSetting("download_directory", event.target.value);
2017-05-17 10:10:25 +02:00
}
onKeyFeeChange(event) {
var oldSettings = this.props.daemonSettings.max_key_fee;
var newSettings = {
amount: oldSettings.amount,
currency: oldSettings.currency,
};
newSettings.amount = Number(event.target.value);
this.setDaemonSetting("max_key_fee", newSettings);
}
onFeeCurrencyChange(event) {
var oldSettings = this.props.daemonSettings.max_key_fee;
var newSettings = {
amount: oldSettings.amount,
currency: oldSettings.currency,
};
newSettings.currency = event.target.value;
this.setDaemonSetting("max_key_fee", newSettings);
}
onKeyFeeDisableChange(isDisabled) {
this.setDaemonSetting("disable_max_key_fee", isDisabled);
}
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) {
2017-06-28 09:12:01 +02:00
this.props.setClientSetting("showNsfw", event.target.checked);
2017-05-17 10:10:25 +02:00
}
// onLanguageChange(language) {
// lbry.setClientSetting('language', language);
// i18n.setLocale(language);
// this.setState({language: language})
// }
2017-06-06 23:19:12 +02:00
onShowUnavailableChange(event) {}
2017-04-12 16:55:19 +02:00
2017-05-17 10:10:25 +02:00
render() {
2017-06-06 23:19:12 +02:00
const { daemonSettings } = 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>
</main>
);
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>
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.")}
onChange={this.onDownloadDirChange.bind(this)}
/>
2017-04-10 14:32:40 +02:00
</div>
2016-04-10 02:00:56 +02:00
</section>
<section className="card">
<div className="card__content">
2017-07-25 16:10:05 +02:00
<h3>{__("Max Purchase Price")}</h3>
</div>
<div className="card__content">
<div className="form-row__label-row">
<div className="form-field__label">
{__("Max Purchase Price")}
</div>
</div>
<FormRow
type="radio"
name="max_key_fee"
onClick={() => {
this.onKeyFeeDisableChange(true);
}}
defaultChecked={daemonSettings.disable_max_key_fee}
label={__("No Limit")}
/>
<div className="form-row">
<FormField
type="radio"
name="max_key_fee"
onClick={() => {
this.onKeyFeeDisableChange(false);
}}
defaultChecked={!daemonSettings.disable_max_key_fee}
label={
daemonSettings.disable_max_key_fee
? __("Choose limit")
: __("Limit to")
}
/>
{!daemonSettings.disable_max_key_fee
? <FormField
type="number"
min="0"
placeholder="50"
step="1"
onChange={this.onKeyFeeChange.bind(this)}
defaultValue={daemonSettings.max_key_fee.amount}
className="form-field__input--inline"
/>
: ""}
{!daemonSettings.disable_max_key_fee
? <FormField
type="select"
onChange={this.onFeeCurrencyChange.bind(this)}
defaultValue={daemonSettings.max_key_fee.currency}
className="form-field__input--inline"
>
<option value="USD">{__("US Dollars")}</option>
<option value="LBC">{__("LBRY credits")}</option>
</FormField>
: ""}
</div>
<div className="form-field__helper">
{__(
2017-07-25 16:07:17 +02:00
"This will prevent you from purchasing any content over this cost, as a safety measure."
)}
</div>
</div>
</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-06-06 23:19:12 +02:00
<FormRow
type="checkbox"
onChange={this.onShowUnavailableChange.bind(this)}
defaultChecked={this.state.showUnavailable}
label={__("Show unavailable content in search results")}
/>
</div>
2017-04-10 14:32:40 +02:00
<div className="card__content">
2017-06-06 23:19:12 +02:00
<FormRow
label={__("Show NSFW content")}
type="checkbox"
onChange={this.onShowNsfwChange.bind(this)}
2017-06-28 09:12:01 +02:00
defaultChecked={this.props.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. "
)}
/>
</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">
<h3>{__("Share Diagnostic Data")}</h3>
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-04-10 14:32:40 +02:00
</div>
2016-04-10 02:00:56 +02:00
</section>
<section className="card">
<div className="card__content">
<h3>{__("Application Cache")}</h3>
</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;