Add error to RHS reply box for messages > 4000 chars, consistent with create post and edit post errors (#4871)

* functionality

* CSS updates

* cleanup

* moved message length checks to Textbox component

* cleanup
Этот коммит содержится в:
Nick Frazier
2016-12-26 09:25:50 -05:00
коммит произвёл Christopher Speller
родитель 87d84dfc30
Коммит 0a1b0d051a
7 изменённых файлов: 89 добавлений и 58 удалений

Просмотреть файл

@@ -32,6 +32,7 @@ export default class Textbox extends React.Component {
this.handleBlur = this.handleBlur.bind(this);
this.handleHeightChange = this.handleHeightChange.bind(this);
this.showPreview = this.showPreview.bind(this);
this.handleChange = this.handleChange.bind(this);
this.state = {
connection: ''
@@ -51,6 +52,10 @@ export default class Textbox extends React.Component {
ErrorStore.addChangeListener(this.onRecievedError);
}
componentWillMount() {
this.checkMessageLength(this.props.value);
}
componentWillUnmount() {
ErrorStore.removeChangeListener(this.onRecievedError);
}
@@ -65,6 +70,30 @@ export default class Textbox extends React.Component {
}
}
handleChange(e) {
this.checkMessageLength(e.target.value);
this.props.onChange(e);
}
checkMessageLength(message) {
if (this.props.handlePostError) {
if (message.length > Constants.CHARACTER_LIMIT) {
const errorMessage = (
<FormattedMessage
id='create_post.error_message'
defaultMessage='Your message is too long. Character count: {length}/{limit}'
values={{
length: message.length,
limit: Constants.CHARACTER_LIMIT
}}
/>);
this.props.handlePostError(errorMessage);
} else {
this.props.handlePostError(null);
}
}
}
handleKeyPress(e) {
this.props.onKeyPress(e);
}
@@ -206,7 +235,7 @@ export default class Textbox extends React.Component {
type='textarea'
spellCheck='true'
placeholder={this.props.createMessage}
onChange={this.props.onChange}
onChange={this.handleChange}
onKeyPress={this.handleKeyPress}
onKeyDown={this.handleKeyDown}
onBlur={this.handleBlur}
@@ -257,5 +286,6 @@ Textbox.propTypes = {
createMessage: React.PropTypes.string.isRequired,
onKeyDown: React.PropTypes.func,
onBlur: React.PropTypes.func,
supportsCommands: React.PropTypes.bool.isRequired
supportsCommands: React.PropTypes.bool.isRequired,
handlePostError: React.PropTypes.func
};