From 174ad90fd754441c4384cc9603399b694fd21e22 Mon Sep 17 00:00:00 2001 From: Terence Ge Date: Fri, 29 Jun 2018 18:31:57 +0800 Subject: [PATCH] update --- shared/sagas/intl.ts | 6 ++--- shared/screens/Profile/Languages/index.jsx | 29 ++++++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/shared/sagas/intl.ts b/shared/sagas/intl.ts index 82cfd4e60..9e7537a2c 100644 --- a/shared/sagas/intl.ts +++ b/shared/sagas/intl.ts @@ -1,10 +1,10 @@ -import { takeEvery } from 'redux-saga/effects' +import { takeEvery, call } from 'redux-saga/effects' import { Action } from 'redux-actions' import storage from 'utils/storage' import * as actions from 'actions/intl' -function setLocale(action: Action) { - storage.setItem('bitportal_lang', action.payload, false, { +function* setLocale(action: Action) { + yield call(storage.setItem, 'bitportal_lang', action.payload, false, { path: '/', domain: 'bitportal.io', expires: new Date(Date.now() + (3600 * 1000 * 24 * 365)) diff --git a/shared/screens/Profile/Languages/index.jsx b/shared/screens/Profile/Languages/index.jsx index ace8e9225..fdea62a60 100644 --- a/shared/screens/Profile/Languages/index.jsx +++ b/shared/screens/Profile/Languages/index.jsx @@ -31,21 +31,34 @@ export default class Languages extends BaseScreen { navBarHidden: true } - changeTabLabels = (tabLabels) => { + constructor(props, context) { + super(props, context) + this.state = { + locale: this.props.locale + } + + this.switchLanguage = this.switchLanguage.bind(this) + this.changeTabLabels = this.changeTabLabels.bind(this) + } + + changeTabLabels(tabLabels) { this.props.navigator.setTabButton({ tabIndex: 0, label: tabLabels.general_tab_name_ast }) this.props.navigator.setTabButton({ tabIndex: 1, label: tabLabels.general_tab_name_mkt }) this.props.navigator.setTabButton({ tabIndex: 2, label: tabLabels.general_tab_name_dscv }) this.props.navigator.setTabButton({ tabIndex: 3, label: tabLabels.general_tab_name_prf }) } - switchLanguage = (language) => { - this.props.actions.setLocale(language) - const tabLabels = tabMessages[language] - this.changeTabLabels(tabLabels) + switchLanguage(language) { + this.setState({ locale: language }, () => { + this.props.actions.setLocale(language) + const tabLabels = tabMessages[language] + this.changeTabLabels(tabLabels) + }) } render() { - const { locale } = this.props + const locale = this.state.locale || this.props.locale + return ( @@ -57,7 +70,7 @@ export default class Languages extends BaseScreen { this.switchLanguage('en')} + onPress={this.switchLanguage.bind(this, 'en')} extraStyle={{ marginTop: 10 }} iconColor={Colors.bgColor_0_122_255} rightItemTitle={locale === 'en' ? null : ' '} @@ -68,7 +81,7 @@ export default class Languages extends BaseScreen { iconColor={Colors.bgColor_0_122_255} rightItemTitle={locale === 'zh' ? null : ' '} rightImageName={locale === 'zh' && 'md-checkmark'} - onPress={() => this.switchLanguage('zh')} + onPress={this.switchLanguage.bind(this, 'zh')} />