From 879a6ef6562f4dc1707d0b4fd1ced4066844d466 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Mon, 23 Dec 2019 12:10:55 +0100 Subject: [PATCH] :zap: factorize maxTootCharsLimit to only have one setting in the compose form --- .../compose/components/compose_form.js | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index cacdd2986..b52bffbce 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -46,6 +46,7 @@ class ComposeForm extends ImmutablePureComponent { spoilerText : PropTypes.string, focusDate : PropTypes.instanceOf(Date), caretPosition : PropTypes.number, + maxTootCharsLimit : PropTypes.number, preselectDate : PropTypes.instanceOf(Date), isSubmitting : PropTypes.bool, isChangingUpload : PropTypes.bool, @@ -64,7 +65,8 @@ class ComposeForm extends ImmutablePureComponent { }; static defaultProps = { - showSearch: false, + showSearch : false, + maxTootCharsLimit: 7777, }; handleChange = (e) => { @@ -88,7 +90,7 @@ class ComposeForm extends ImmutablePureComponent { const { isSubmitting, isChangingUpload, isUploading, anyMedia } = this.props; const fulltext = [this.props.spoilerText, countableText(this.props.text)].join(''); - if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > 7777 || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) { + if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > this.props.maxTootCharsLimit || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) { return; } @@ -181,23 +183,26 @@ class ComposeForm extends ImmutablePureComponent { const { intl, onPaste, showSearch, anyMedia } = this.props; const disabled = this.props.isSubmitting; const text = [this.props.spoilerText, countableText(this.props.text)].join(''); - const disabledButton = disabled || this.props.isUploading || this.props.isChangingUpload || length(text) > 7777 || (text.length !== 0 && text.trim().length === 0 && !anyMedia); + const disabledButton = disabled || this.props.isUploading || this.props.isChangingUpload || length(text) > this.props.maxTootCharsLimit || (text.length !== 0 && text.trim().length === 0 && !anyMedia); let publishText = ''; if (this.props.privacy === 'private' || this.props.privacy === 'direct') { publishText = - {intl.formatMessage(messages.publish)}; + {intl.formatMessage(messages.publish)}; } else { publishText = this.props.privacy !== 'unlisted' ? intl.formatMessage(messages.publishLoud, { publish: intl.formatMessage(messages.publish) }) : intl.formatMessage(messages.publish); } return (
- + - + -
+
-
+
- +
- - -
-
+ + +
+
- - - - -
-
-
+ + + + + +
+
-
+ text={publishText} + onClick={this.handleSubmit} + disabled={disabledButton} + block + /> + - + ); }