Skip to content

Commit

Permalink
Fix submitting post from content warning field not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Dec 21, 2023
1 parent dac2b56 commit 5cf3f15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ class ComposeForm extends ImmutablePureComponent {
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (!fulltext.trim().length && !anyMedia));
};

handleSubmit = (overriddenVisibility = null) => {
handleSubmit = (e, overriddenVisibility = null) => {
overriddenVisibility = overriddenVisibility || e?.submitter?.dataset?.visibility;

if (this.props.text !== this.textareaRef.current.value) {
// Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
// Update the state to match the current text
Expand All @@ -136,6 +138,10 @@ class ComposeForm extends ImmutablePureComponent {
return;
}

if (e) {
e.preventDefault();
}

// Submit unless there are media with missing descriptions
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'));
Expand All @@ -150,10 +156,8 @@ class ComposeForm extends ImmutablePureComponent {

// Handles the secondary submit button.
handleSecondarySubmit = () => {
const {
sideArm,
} = this.props;
this.handleSubmit(sideArm === 'none' ? null : sideArm);
const { sideArm } = this.props;
this.handleSubmit(null, sideArm === 'none' ? null : sideArm);
};

onSuggestionsClearRequested = () => {
Expand Down Expand Up @@ -341,8 +345,6 @@ class ComposeForm extends ImmutablePureComponent {
<Publisher
disabled={!this.canSubmit()}
isEditing={isEditing}
onSecondarySubmit={this.handleSecondarySubmit}
onSubmit={this.handleSubmit}
privacy={privacy}
sideArm={sideArm}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ class Publisher extends ImmutablePureComponent {
static propTypes = {
disabled: PropTypes.bool,
intl: PropTypes.object.isRequired,
onSecondarySubmit: PropTypes.func,
onSubmit: PropTypes.func,
privacy: PropTypes.oneOf(['direct', 'private', 'unlisted', 'public']),
sideArm: PropTypes.oneOf(['none', 'direct', 'private', 'unlisted', 'public']),
isEditing: PropTypes.bool,
};

handleSubmit = () => {
this.props.onSubmit();
};

render () {
const { disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;
const { disabled, intl, privacy, sideArm, isEditing } = this.props;

const privacyIcons = { direct: 'envelope', private: 'lock', public: 'globe', unlisted: 'unlock' };

Expand Down Expand Up @@ -71,20 +65,21 @@ class Publisher extends ImmutablePureComponent {
<div className='compose-form__publish-button-wrapper'>
<Button
className='side_arm'
type='submit'
disabled={disabled}
onClick={onSecondarySubmit}
style={{ padding: null }}
text={<Icon id={privacyIcons[sideArm]} />}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[sideArm])}`}
data-visibility={sideArm}
/>
</div>
)}
<div className='compose-form__publish-button-wrapper'>
<Button
className='primary'
type='submit'
text={publishText}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`}
onClick={this.handleSubmit}
disabled={disabled}
/>
</div>
Expand Down

0 comments on commit 5cf3f15

Please sign in to comment.