Fix submitting post from content warning field not working properly (#2538)

This commit is contained in:
Claire 2023-12-22 17:23:15 +01:00 committed by GitHub
parent e676b57831
commit 72ff0d30d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View file

@ -125,7 +125,7 @@ class ComposeForm extends ImmutablePureComponent {
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (!fulltext.trim().length && !anyMedia)); return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (!fulltext.trim().length && !anyMedia));
}; };
handleSubmit = (overriddenVisibility = null) => { handleSubmit = (e, overriddenVisibility = null) => {
if (this.props.text !== this.textareaRef.current.value) { if (this.props.text !== this.textareaRef.current.value) {
// Something changed the text inside the textarea (e.g. browser extensions like Grammarly) // Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
// Update the state to match the current text // Update the state to match the current text
@ -136,6 +136,10 @@ class ComposeForm extends ImmutablePureComponent {
return; return;
} }
if (e) {
e.preventDefault();
}
// Submit unless there are media with missing descriptions // Submit unless there are media with missing descriptions
if (this.props.mediaDescriptionConfirmation && this.props.media && this.props.media.some(item => !item.get('description'))) { if (this.props.mediaDescriptionConfirmation && this.props.media && this.props.media.some(item => !item.get('description'))) {
const firstWithoutDescription = this.props.media.find(item => !item.get('description')); const firstWithoutDescription = this.props.media.find(item => !item.get('description'));
@ -150,10 +154,8 @@ class ComposeForm extends ImmutablePureComponent {
// Handles the secondary submit button. // Handles the secondary submit button.
handleSecondarySubmit = () => { handleSecondarySubmit = () => {
const { const { sideArm } = this.props;
sideArm, this.handleSubmit(null, sideArm === 'none' ? null : sideArm);
} = this.props;
this.handleSubmit(sideArm === 'none' ? null : sideArm);
}; };
onSuggestionsClearRequested = () => { onSuggestionsClearRequested = () => {
@ -342,7 +344,6 @@ class ComposeForm extends ImmutablePureComponent {
disabled={!this.canSubmit()} disabled={!this.canSubmit()}
isEditing={isEditing} isEditing={isEditing}
onSecondarySubmit={this.handleSecondarySubmit} onSecondarySubmit={this.handleSecondarySubmit}
onSubmit={this.handleSubmit}
privacy={privacy} privacy={privacy}
sideArm={sideArm} sideArm={sideArm}
/> />

View file

@ -29,16 +29,11 @@ class Publisher extends ImmutablePureComponent {
disabled: PropTypes.bool, disabled: PropTypes.bool,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
onSecondarySubmit: PropTypes.func, onSecondarySubmit: PropTypes.func,
onSubmit: PropTypes.func,
privacy: PropTypes.oneOf(['direct', 'private', 'unlisted', 'public']), privacy: PropTypes.oneOf(['direct', 'private', 'unlisted', 'public']),
sideArm: PropTypes.oneOf(['none', 'direct', 'private', 'unlisted', 'public']), sideArm: PropTypes.oneOf(['none', 'direct', 'private', 'unlisted', 'public']),
isEditing: PropTypes.bool, isEditing: PropTypes.bool,
}; };
handleSubmit = () => {
this.props.onSubmit();
};
render () { render () {
const { disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props; const { disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;
@ -82,9 +77,9 @@ class Publisher extends ImmutablePureComponent {
<div className='compose-form__publish-button-wrapper'> <div className='compose-form__publish-button-wrapper'>
<Button <Button
className='primary' className='primary'
type='submit'
text={publishText} text={publishText}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`} title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`}
onClick={this.handleSubmit}
disabled={disabled} disabled={disabled}
/> />
</div> </div>