Trying to get redux stuff to work...

This commit is contained in:
Fillerino 2017-07-07 15:15:45 +02:00
parent d41c9295bd
commit d733a7b1b4
6 changed files with 25 additions and 8 deletions

View file

@ -248,3 +248,11 @@ export function doClearCache() {
return Promise.resolve(); return Promise.resolve();
}; };
} }
export function doChangeLanguage(newLanguage) {
app.i18n.setLocale(newLanguage);
return {
type: types.CHANGE_LANGUAGE,
data: { newLanguage: newLanguage }
}
}

View file

@ -97,3 +97,6 @@ export const CLAIM_REWARD_STARTED = "CLAIM_REWARD_STARTED";
export const CLAIM_REWARD_SUCCESS = "CLAIM_REWARD_SUCCESS"; export const CLAIM_REWARD_SUCCESS = "CLAIM_REWARD_SUCCESS";
export const CLAIM_REWARD_FAILURE = "CLAIM_REWARD_FAILURE"; export const CLAIM_REWARD_FAILURE = "CLAIM_REWARD_FAILURE";
export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR"; export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR";
//Language
export const LANGUAGE_CHANGED = "LANGUAGE_CHANGED";

View file

@ -1,19 +1,21 @@
import React from "react"; import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { doClearCache } from "actions/app"; import { doClearCache } from "actions/app";
import { doSetDaemonSetting, doSetClientSetting } from "actions/settings"; import { doSetDaemonSetting, doSetClientSetting, doChangeLanguage } from "actions/settings";
import { selectDaemonSettings, selectShowNsfw } from "selectors/settings"; import { selectDaemonSettings, selectShowNsfw, selectCurrentLanguage } from "selectors/settings";
import SettingsPage from "./view"; import SettingsPage from "./view";
const select = state => ({ const select = state => ({
daemonSettings: selectDaemonSettings(state), daemonSettings: selectDaemonSettings(state),
showNsfw: selectShowNsfw(state), showNsfw: selectShowNsfw(state),
language: selectCurrentLanguage(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)), setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
clearCache: () => dispatch(doClearCache()), clearCache: () => dispatch(doClearCache()),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
changeLanguage: (newLanguage) => dispatch(doChangeLanguage),
}); });
export default connect(select, perform)(SettingsPage); export default connect(select, perform)(SettingsPage);

View file

@ -85,10 +85,8 @@ class SettingsPage extends React.PureComponent {
this.props.setClientSetting("showNsfw", event.target.checked); this.props.setClientSetting("showNsfw", event.target.checked);
} }
onLanguageChange(language) { onLanguageChange(e) {
lbry.setClientSetting('language', language); this.props.changeLanguage(e.target.value)
window.app.i18n.setLocale(language);
this.setState({language: language})
} }
// onLanguageChange(language) { // onLanguageChange(language) {
@ -168,7 +166,7 @@ class SettingsPage extends React.PureComponent {
name="language" name="language"
label={__("English")} label={__("English")}
onChange={() => { onChange={() => {
this.onLanguageChange("en"); this.onLanguageChange.bind(this);
}} }}
defaultChecked={this.state.language == "en"} defaultChecked={this.state.language == "en"}
/> />
@ -181,7 +179,7 @@ class SettingsPage extends React.PureComponent {
key={dLang} key={dLang}
label={window.app.i18n.resLang(dLang)} label={window.app.i18n.resLang(dLang)}
onChange={() => { onChange={() => {
this.onLanguageChange(dLang); this.onLanguageChange.bind(this);
}} }}
defaultChecked={this.state.language == dLang} defaultChecked={this.state.language == dLang}
/> />

View file

@ -5,6 +5,7 @@ const reducers = {};
const defaultState = { const defaultState = {
clientSettings: { clientSettings: {
showNsfw: lbry.getClientSetting("showNsfw"), showNsfw: lbry.getClientSetting("showNsfw"),
language: lbry.getClientSetting("language"),
}, },
}; };

View file

@ -191,3 +191,8 @@ export const selectBadgeNumber = createSelector(
_selectState, _selectState,
state => state.badgeNumber state => state.badgeNumber
); );
export const selectCurrentLanguage = createSelector(
_selectState,
(state) => state.currentLanguage || "en"
)