Trying to get redux stuff to work...
This commit is contained in:
parent
d41c9295bd
commit
d733a7b1b4
6 changed files with 25 additions and 8 deletions
|
@ -248,3 +248,11 @@ export function doClearCache() {
|
|||
return Promise.resolve();
|
||||
};
|
||||
}
|
||||
|
||||
export function doChangeLanguage(newLanguage) {
|
||||
app.i18n.setLocale(newLanguage);
|
||||
return {
|
||||
type: types.CHANGE_LANGUAGE,
|
||||
data: { newLanguage: newLanguage }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,3 +97,6 @@ export const CLAIM_REWARD_STARTED = "CLAIM_REWARD_STARTED";
|
|||
export const CLAIM_REWARD_SUCCESS = "CLAIM_REWARD_SUCCESS";
|
||||
export const CLAIM_REWARD_FAILURE = "CLAIM_REWARD_FAILURE";
|
||||
export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR";
|
||||
|
||||
//Language
|
||||
export const LANGUAGE_CHANGED = "LANGUAGE_CHANGED";
|
|
@ -1,19 +1,21 @@
|
|||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { doClearCache } from "actions/app";
|
||||
import { doSetDaemonSetting, doSetClientSetting } from "actions/settings";
|
||||
import { selectDaemonSettings, selectShowNsfw } from "selectors/settings";
|
||||
import { doSetDaemonSetting, doSetClientSetting, doChangeLanguage } from "actions/settings";
|
||||
import { selectDaemonSettings, selectShowNsfw, selectCurrentLanguage } from "selectors/settings";
|
||||
import SettingsPage from "./view";
|
||||
|
||||
const select = state => ({
|
||||
daemonSettings: selectDaemonSettings(state),
|
||||
showNsfw: selectShowNsfw(state),
|
||||
language: selectCurrentLanguage(state),
|
||||
});
|
||||
|
||||
const perform = dispatch => ({
|
||||
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
|
||||
clearCache: () => dispatch(doClearCache()),
|
||||
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
||||
changeLanguage: (newLanguage) => dispatch(doChangeLanguage),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(SettingsPage);
|
||||
|
|
|
@ -85,10 +85,8 @@ class SettingsPage extends React.PureComponent {
|
|||
this.props.setClientSetting("showNsfw", event.target.checked);
|
||||
}
|
||||
|
||||
onLanguageChange(language) {
|
||||
lbry.setClientSetting('language', language);
|
||||
window.app.i18n.setLocale(language);
|
||||
this.setState({language: language})
|
||||
onLanguageChange(e) {
|
||||
this.props.changeLanguage(e.target.value)
|
||||
}
|
||||
|
||||
// onLanguageChange(language) {
|
||||
|
@ -168,7 +166,7 @@ class SettingsPage extends React.PureComponent {
|
|||
name="language"
|
||||
label={__("English")}
|
||||
onChange={() => {
|
||||
this.onLanguageChange("en");
|
||||
this.onLanguageChange.bind(this);
|
||||
}}
|
||||
defaultChecked={this.state.language == "en"}
|
||||
/>
|
||||
|
@ -181,7 +179,7 @@ class SettingsPage extends React.PureComponent {
|
|||
key={dLang}
|
||||
label={window.app.i18n.resLang(dLang)}
|
||||
onChange={() => {
|
||||
this.onLanguageChange(dLang);
|
||||
this.onLanguageChange.bind(this);
|
||||
}}
|
||||
defaultChecked={this.state.language == dLang}
|
||||
/>
|
||||
|
|
|
@ -5,6 +5,7 @@ const reducers = {};
|
|||
const defaultState = {
|
||||
clientSettings: {
|
||||
showNsfw: lbry.getClientSetting("showNsfw"),
|
||||
language: lbry.getClientSetting("language"),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -191,3 +191,8 @@ export const selectBadgeNumber = createSelector(
|
|||
_selectState,
|
||||
state => state.badgeNumber
|
||||
);
|
||||
|
||||
export const selectCurrentLanguage = createSelector(
|
||||
_selectState,
|
||||
(state) => state.currentLanguage || "en"
|
||||
)
|
Loading…
Reference in a new issue