Only update Client4.setAcceptLanguage when locale changes (#1942)

This commit is contained in:
Harrison Healey 2018-07-26 07:54:33 -04:00 committed by Elias Nahum
parent 0272cd5d47
commit 154def4af8
2 changed files with 9 additions and 2 deletions

View file

@ -3,7 +3,6 @@
import {connect} from 'react-redux';
import {Client4} from 'mattermost-redux/client';
import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentUrl} from 'mattermost-redux/selectors/entities/general';
@ -15,7 +14,6 @@ import Root from './root';
function mapStateToProps(state) {
const locale = getCurrentLocale(state);
Client4.setAcceptLanguage(locale);
return {
theme: getTheme(state),

View file

@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
import {IntlProvider} from 'react-intl';
import {Platform} from 'react-native';
import {Client4} from 'mattermost-redux/client';
import EventEmitter from 'mattermost-redux/utils/event_emitter';
import {NavigationTypes, ViewTypes} from 'app/constants';
@ -23,6 +24,8 @@ export default class Root extends PureComponent {
};
componentWillMount() {
Client4.setAcceptLanguage(this.props.locale);
if (!this.props.excludeEvents) {
EventEmitter.on(ViewTypes.NOTIFICATION_IN_APP, this.handleInAppNotification);
EventEmitter.on(ViewTypes.NOTIFICATION_TAPPED, this.handleNotificationTapped);
@ -30,6 +33,12 @@ export default class Root extends PureComponent {
}
}
componentDidUpdate(prevProps) {
if (prevProps.locale !== this.props.locale) {
Client4.setAcceptLanguage(this.props.locale);
}
}
componentWillUnmount() {
if (!this.props.excludeEvents) {
EventEmitter.off(ViewTypes.NOTIFICATION_IN_APP, this.handleInAppNotification);