From 0816e7a848aa20d66dff453e73399a5d05edc02e Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 28 May 2016 00:36:10 +0300 Subject: [PATCH] #106: recalculate form height, after lang changed --- src/components/auth/PanelTransition.jsx | 2 +- src/components/profile/changeEmail/ChangeEmail.jsx | 3 ++- src/components/ui/form/Form.jsx | 5 +++-- src/components/ui/form/FormModel.js | 10 ++++++++-- src/pages/profile/ChangeEmailPage.jsx | 5 ++++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/auth/PanelTransition.jsx b/src/components/auth/PanelTransition.jsx index 190595c..bf4699a 100644 --- a/src/components/auth/PanelTransition.jsx +++ b/src/components/auth/PanelTransition.jsx @@ -316,7 +316,7 @@ class PanelTransition extends Component { } shouldMeasureHeight() { - return '' + this.props.auth.error + this.state.isHeightDirty; + return '' + this.props.auth.error + this.state.isHeightDirty + this.props.user.lang; } getHeader({key, style, data}) { diff --git a/src/components/profile/changeEmail/ChangeEmail.jsx b/src/components/profile/changeEmail/ChangeEmail.jsx index 7caae3f..3257da9 100644 --- a/src/components/profile/changeEmail/ChangeEmail.jsx +++ b/src/components/profile/changeEmail/ChangeEmail.jsx @@ -22,6 +22,7 @@ export default class ChangeEmail extends Component { static propTypes = { onChangeStep: PropTypes.func, + lang: PropTypes.string.isRequired, email: PropTypes.string.isRequired, stepForms: PropTypes.arrayOf((propValue, key, componentName, location, propFullName) => { if (propValue.length !== 3) { @@ -161,7 +162,7 @@ export default class ChangeEmail extends Component { {this[`renderStep${step}`]({ diff --git a/src/components/ui/form/Form.jsx b/src/components/ui/form/Form.jsx index 28b8efa..98ce970 100644 --- a/src/components/ui/form/Form.jsx +++ b/src/components/ui/form/Form.jsx @@ -52,8 +52,9 @@ export default class Form extends Component { }); } - if (nextProps.form && nextProps.form !== this.props.form) { - throw new Error('The FormModel instance should not be changed during component lifetime'); + if (nextProps.form && this.props.form && nextProps.form !== this.props.form) { + this.props.form.removeLoadingListener(this.onLoading); + nextProps.form.addLoadingListener(this.onLoading); } } diff --git a/src/components/ui/form/FormModel.js b/src/components/ui/form/FormModel.js index 45d53f9..35ee711 100644 --- a/src/components/ui/form/FormModel.js +++ b/src/components/ui/form/FormModel.js @@ -105,10 +105,16 @@ export default class FormModel { } beginLoading() { - this.handlers.forEach((fn) => fn(true)); + this._isLoading = true; + this.notifyHandlers(); } endLoading() { - this.handlers.forEach((fn) => fn(false)); + this._isLoading = false; + this.notifyHandlers(); + } + + notifyHandlers() { + this.handlers.forEach((fn) => fn(this._isLoading)); } } diff --git a/src/pages/profile/ChangeEmailPage.jsx b/src/pages/profile/ChangeEmailPage.jsx index 5a40dc7..279319d 100644 --- a/src/pages/profile/ChangeEmailPage.jsx +++ b/src/pages/profile/ChangeEmailPage.jsx @@ -9,6 +9,7 @@ class ChangeEmailPage extends Component { static propTypes = { email: PropTypes.string.isRequired, + lang: PropTypes.string.isRequired, params: PropTypes.shape({ step: PropTypes.oneOf(['step1', 'step2', 'step3']), code: PropTypes.string @@ -40,6 +41,7 @@ class ChangeEmailPage extends Component { ({ - email: state.user.email + email: state.user.email, + lang: state.user.lang }), { })(ChangeEmailPage);