diff options
author | Claire <claire.github-309c@sitedethib.com> | 2020-12-05 17:33:29 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2020-12-05 17:33:37 +0100 |
commit | f8d867bac43e7e18d293ac32a9be597d1f46dce3 (patch) | |
tree | b3d950a01a8dee5403081f56cf0c6b0571954e90 /app/javascript/mastodon/features/compose | |
parent | 13df125b6c75923ccc21a5c57053e680cea75f38 (diff) | |
parent | 44d5c6bc8ffd92cd201380dabe35748e50b6af68 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - `app/services/remove_status_service.rb`: Conflict caused by us having a distinc Direct timeline. Ported upstream changes. - `app/javascript/mastodon/features/compose/components/compose_form.js`: Conflict between glitch-soc's variable character limit and upstream refactoring that part of the code. Ported upstream changes.
Diffstat (limited to 'app/javascript/mastodon/features/compose')
-rw-r--r-- | app/javascript/mastodon/features/compose/components/compose_form.js | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index 46c52d9e4..adec8dc8b 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -78,6 +78,18 @@ class ComposeForm extends ImmutablePureComponent { } } + getFulltextForCharacterCounting = () => { + return [this.props.spoiler? this.props.spoilerText: '', countableText(this.props.text)].join(''); + } + + canSubmit = () => { + const { isSubmitting, isChangingUpload, isUploading, anyMedia } = this.props; + const fulltext = this.getFulltextForCharacterCounting(); + const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0; + + return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (isOnlyWhitespace && !anyMedia)); + } + handleSubmit = () => { if (this.props.text !== this.autosuggestTextarea.textarea.value) { // Something changed the text inside the textarea (e.g. browser extensions like Grammarly) @@ -85,11 +97,7 @@ class ComposeForm extends ImmutablePureComponent { this.props.onChange(this.autosuggestTextarea.textarea.value); } - // Submit disabled: - const { isSubmitting, isChangingUpload, isUploading, anyMedia } = this.props; - const fulltext = [this.props.spoilerText, countableText(this.props.text)].join(''); - - if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) { + if (!this.canSubmit()) { return; } @@ -179,10 +187,8 @@ class ComposeForm extends ImmutablePureComponent { } render () { - const { intl, onPaste, showSearch, anyMedia } = this.props; + const { intl, onPaste, showSearch } = 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) > maxChars || (text.length !== 0 && text.trim().length === 0 && !anyMedia); let publishText = ''; if (this.props.privacy === 'private' || this.props.privacy === 'direct') { @@ -244,11 +250,11 @@ class ComposeForm extends ImmutablePureComponent { <PrivacyDropdownContainer /> <SpoilerButtonContainer /> </div> - <div className='character-counter__wrapper'><CharacterCounter max={maxChars} text={text} /></div> + <div className='character-counter__wrapper'><CharacterCounter max={maxChars} text={this.getFulltextForCharacterCounting()} /></div> </div> <div className='compose-form__publish'> - <div className='compose-form__publish-button-wrapper'><Button text={publishText} onClick={this.handleSubmit} disabled={disabledButton} block /></div> + <div className='compose-form__publish-button-wrapper'><Button text={publishText} onClick={this.handleSubmit} disabled={!this.canSubmit()} block /></div> </div> </div> ); |