From 120944cb25bbd3986a236c3e444e1d6262509f1d Mon Sep 17 00:00:00 2001 From: Daniil Senkiv Date: Wed, 22 Jan 2020 16:00:42 +0300 Subject: [PATCH] Web.Client: Settings: Article: Body: fixed re-render after changing language, if user language not defined --- .../Settings/Layout/Article/Body/index.js | 26 ++++++++++--------- web/ASC.Web.Common/src/store/auth/reducer.js | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/web/ASC.Web.Client/src/components/pages/Settings/Layout/Article/Body/index.js b/web/ASC.Web.Client/src/components/pages/Settings/Layout/Article/Body/index.js index b6f7afce01..0898c31b53 100644 --- a/web/ASC.Web.Client/src/components/pages/Settings/Layout/Article/Body/index.js +++ b/web/ASC.Web.Client/src/components/pages/Settings/Layout/Article/Body/index.js @@ -1,16 +1,20 @@ import React from 'react'; -import { utils } from 'asc-web-components'; -import { connect } from 'react-redux'; import { TreeMenu, TreeNode, Icons, - Link + Link, + utils } from "asc-web-components"; import { withRouter } from "react-router"; import styled from 'styled-components'; import { withTranslation } from 'react-i18next'; import { getKeyByLink, settingsTree, getSelectedLinkByKey, selectKeyOfTreeElement } from '../../../utils'; +import { constants, utils as commonUtils } from 'asc-web-common'; +import i18n from '../../../i18n'; + +const { changeLanguage } = commonUtils; +const { LANGUAGE } = constants; const StyledTreeMenu = styled(TreeMenu)` .inherit-title-link { @@ -58,10 +62,9 @@ class ArticleBodyContent extends React.Component { constructor(props) { super(props); - const { match, history, i18n, language } = props; + const { match, history } = props; const fullSettingsUrl = props.match.url; const locationPathname = props.location.pathname; - i18n.changeLanguage(language); if (locationPathname === fullSettingsUrl) { const defaultKey = ['0']; @@ -114,6 +117,10 @@ class ArticleBodyContent extends React.Component { return true; } + if (this.props.i18n.language !== localStorage.getItem(LANGUAGE)) { + return true; + } + return false; } @@ -144,6 +151,7 @@ class ArticleBodyContent extends React.Component { }; render() { + changeLanguage(i18n); const { selectedKeys } = this.state; const { match, t } = this.props; @@ -168,10 +176,4 @@ class ArticleBodyContent extends React.Component { }; }; -function mapStateToProps(state) { - return { - language: state.auth.user.cultureName || state.auth.settings.culture, - }; -} - -export default connect(mapStateToProps)(withRouter(withTranslation()(ArticleBodyContent))); +export default withRouter(withTranslation()(ArticleBodyContent)); diff --git a/web/ASC.Web.Common/src/store/auth/reducer.js b/web/ASC.Web.Common/src/store/auth/reducer.js index 83357458c7..c244472204 100644 --- a/web/ASC.Web.Common/src/store/auth/reducer.js +++ b/web/ASC.Web.Common/src/store/auth/reducer.js @@ -71,6 +71,9 @@ const authReducer = (state = initialState, action) => { user: { ...state.user, email: action.email } }); case SET_PORTAL_LANGUAGE_AND_TIME: + if (!state.user.cultureName) { + localStorage.setItem(LANGUAGE, action.newSettings.lng); + } return Object.assign({}, state, { settings: { ...state.settings, culture: action.newSettings.lng, timezone: action.newSettings.timeZoneID } });