more settings progress

This commit is contained in:
Jeremy Kauffman 2017-09-06 21:53:42 -04:00
parent ad6b4f4f03
commit 4cc9f46934
8 changed files with 30 additions and 47 deletions

View file

@ -164,7 +164,7 @@ export function doDownloadLanguages() {
export function doChangeLanguage(language) { export function doChangeLanguage(language) {
return function(dispatch, getState) { return function(dispatch, getState) {
lbry.setClientSetting(settings.LANGUAGE, language); dispatch(doSetClientSetting(settings.LANGUAGE, language));
app.i18n.setLocale(language); app.i18n.setLocale(language);
}; };
} }

View file

@ -1,18 +1,13 @@
import store from "store.js"; import store from "store.js";
import lbry from "./lbry.js";
import * as settings from "constants/settings";
const env = ENV; const env = ENV;
const config = { const config = {
...require(`./config/${env}`), ...require(`./config/${env}`),
}; };
const language = lbry.getClientSetting(settings.LANGUAGE)
? lbry.getClientSetting(settings.LANGUAGE)
: "en";
const i18n = require("y18n")({ const i18n = require("y18n")({
directory: "app/locales", directory: "app/locales",
updateFiles: false, updateFiles: false,
locale: language, locale: "en",
}); });
const logs = []; const logs = [];
const app = { const app = {

View file

@ -9,7 +9,6 @@ const Theme = props => {
return ( return (
<link <link
id="theme"
href={themePath} href={themePath}
rel="stylesheet" rel="stylesheet"
type="text/css" type="text/css"

View file

@ -279,17 +279,6 @@ lbry.publishDeprecated = function(
); );
}; };
lbry.getClientSettings = function() {
var outSettings = {};
for (let setting of Object.keys(lbry.defaultClientSettings)) {
var localStorageVal = localStorage.getItem("setting_" + setting);
outSettings[setting] = localStorageVal === null
? lbry.defaultClientSettings[setting]
: JSON.parse(localStorageVal);
}
return outSettings;
};
lbry.getClientSetting = function(setting) { lbry.getClientSetting = function(setting) {
var localStorageVal = localStorage.getItem("setting_" + setting); var localStorageVal = localStorage.getItem("setting_" + setting);
if (setting == "showDeveloperMenu") { if (setting == "showDeveloperMenu") {
@ -300,12 +289,6 @@ lbry.getClientSetting = function(setting) {
: JSON.parse(localStorageVal); : JSON.parse(localStorageVal);
}; };
lbry.setClientSettings = function(settings) {
for (let setting of Object.keys(settings)) {
lbry.setClientSetting(setting, settings[setting]);
}
};
lbry.setClientSetting = function(setting, value) { lbry.setClientSetting = function(setting, value) {
return localStorage.setItem("setting_" + setting, JSON.stringify(value)); return localStorage.setItem("setting_" + setting, JSON.stringify(value));
}; };

View file

@ -12,7 +12,6 @@ import {
import { import {
makeSelectClientSetting, makeSelectClientSetting,
selectDaemonSettings, selectDaemonSettings,
selectShowNsfw,
selectLanguages, selectLanguages,
} from "selectors/settings"; } from "selectors/settings";
import { selectCurrentLanguage } from "selectors/app"; import { selectCurrentLanguage } from "selectors/app";
@ -20,10 +19,12 @@ import SettingsPage from "./view";
const select = state => ({ const select = state => ({
daemonSettings: selectDaemonSettings(state), daemonSettings: selectDaemonSettings(state),
showNsfw: selectShowNsfw(state), showNsfw: makeSelectClientSetting(settings.SHOW_NSFW)(state),
showUnavailable: makeSelectClientSetting(settings.SHOW_UNAVAILABLE)(state),
theme: makeSelectClientSetting(settings.THEME)(state),
themes: makeSelectClientSetting(settings.THEMES)(state),
language: selectCurrentLanguage(state), language: selectCurrentLanguage(state),
languages: selectLanguages(state), languages: selectLanguages(state),
theme: makeSelectClientSetting(settings.THEME)(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({

View file

@ -12,16 +12,8 @@ class SettingsPage extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
const { daemonSettings } = this.props || {};
this.state = { this.state = {
// isMaxUpload: daemonSettings && daemonSettings.max_upload != 0,
// isMaxDownload: daemonSettings && daemonSettings.max_download != 0,
showUnavailable: lbry.getClientSetting(settings.SHOW_UNAVAILABLE),
language: lbry.getClientSetting(settings.LANGUAGE),
clearingCache: false, clearingCache: false,
theme: lbry.getClientSetting(settings.THEME),
themes: lbry.getClientSetting(settings.THEMES),
}; };
} }
@ -102,7 +94,12 @@ class SettingsPage extends React.PureComponent {
this.forceUpdate(); this.forceUpdate();
} }
onShowUnavailableChange(event) {} onShowUnavailableChange(event) {
this.props.setClientSetting(
settings.SHOW_UNAVAILABLE,
event.target.checked
);
}
componentWillMount() { componentWillMount() {
this.props.getThemes(); this.props.getThemes();
@ -111,7 +108,15 @@ class SettingsPage extends React.PureComponent {
componentDidMount() {} componentDidMount() {}
render() { render() {
const { daemonSettings, language, languages, theme } = this.props; const {
daemonSettings,
language,
languages,
showNsfw,
showUnavailable,
theme,
themes,
} = this.props;
if (!daemonSettings || Object.keys(daemonSettings).length === 0) { if (!daemonSettings || Object.keys(daemonSettings).length === 0) {
return ( return (
@ -216,7 +221,7 @@ class SettingsPage extends React.PureComponent {
<FormRow <FormRow
type="checkbox" type="checkbox"
onChange={this.onShowUnavailableChange.bind(this)} onChange={this.onShowUnavailableChange.bind(this)}
defaultChecked={this.state.showUnavailable} defaultChecked={showUnavailable}
label={__("Show unavailable content in search results")} label={__("Show unavailable content in search results")}
/> />
</div> </div>
@ -225,7 +230,7 @@ class SettingsPage extends React.PureComponent {
label={__("Show NSFW content")} label={__("Show NSFW content")}
type="checkbox" type="checkbox"
onChange={this.onShowNsfwChange.bind(this)} onChange={this.onShowNsfwChange.bind(this)}
defaultChecked={this.props.showNsfw} defaultChecked={showNsfw}
helper={__( 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. " "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. "
)} )}
@ -254,13 +259,14 @@ class SettingsPage extends React.PureComponent {
<h3>{__("Theme")}</h3> <h3>{__("Theme")}</h3>
</div> </div>
<div className="card__content"> <div className="card__content">
{console.log(theme)}
<FormField <FormField
type="select" type="select"
onChange={this.onThemeChange.bind(this)} onChange={this.onThemeChange.bind(this)}
value={theme} defaultValue={theme}
className="form-field__input--inline" className="form-field__input--inline"
> >
{this.state.themes.map((theme, index) => {themes.map((theme, index) =>
<option key={theme} value={theme}> <option key={theme} value={theme}>
{theme} {theme}
</option> </option>

View file

@ -6,7 +6,8 @@ import lbry from "lbry";
const reducers = {}; const reducers = {};
const defaultState = { const defaultState = {
clientSettings: { clientSettings: {
showNsfw: lbry.getClientSetting("showNsfw"), showNsfw: lbry.getClientSetting(settings.SHOW_NSFW),
showUnavailable: lbry.getClientSetting(settings.SHOW_UNAVAILABLE),
welcome_acknowledged: lbry.getClientSetting(settings.NEW_USER_ACKNOWLEDGED), welcome_acknowledged: lbry.getClientSetting(settings.NEW_USER_ACKNOWLEDGED),
credit_intro_acknowledged: lbry.getClientSetting( credit_intro_acknowledged: lbry.getClientSetting(
settings.CREDIT_INTRO_ACKNOWLEDGED settings.CREDIT_INTRO_ACKNOWLEDGED

View file

@ -25,10 +25,8 @@ export const selectSettingsIsGenerous = createSelector(
settings => settings && settings.is_generous_host settings => settings && settings.is_generous_host
); );
export const selectShowNsfw = createSelector( //refactor me
selectClientSettings, export const selectShowNsfw = makeSelectClientSetting(settings.SHOW_NSFW);
clientSettings => !!clientSettings.showNsfw
);
export const selectLanguages = createSelector( export const selectLanguages = createSelector(
_selectState, _selectState,