From 72ff0d30d8443ef5d3af264beaa0686943026e2e Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Fri, 22 Dec 2023 17:23:15 +0100
Subject: [PATCH] Fix submitting post from content warning field not working
 properly (#2538)

---
 .../features/compose/components/compose_form.jsx    | 13 +++++++------
 .../features/compose/components/publisher.jsx       |  7 +------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx
index 4ec2b81d11..d815e9db2f 100644
--- a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx
+++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx
@@ -125,7 +125,7 @@ class ComposeForm extends ImmutablePureComponent {
     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) {
       // Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
       // Update the state to match the current text
@@ -136,6 +136,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'));
@@ -150,10 +154,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 = () => {
@@ -342,7 +344,6 @@ class ComposeForm extends ImmutablePureComponent {
           disabled={!this.canSubmit()}
           isEditing={isEditing}
           onSecondarySubmit={this.handleSecondarySubmit}
-          onSubmit={this.handleSubmit}
           privacy={privacy}
           sideArm={sideArm}
         />
diff --git a/app/javascript/flavours/glitch/features/compose/components/publisher.jsx b/app/javascript/flavours/glitch/features/compose/components/publisher.jsx
index 5c3a059294..84490ee523 100644
--- a/app/javascript/flavours/glitch/features/compose/components/publisher.jsx
+++ b/app/javascript/flavours/glitch/features/compose/components/publisher.jsx
@@ -29,16 +29,11 @@ class Publisher extends ImmutablePureComponent {
     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;
 
@@ -82,9 +77,9 @@ class Publisher extends ImmutablePureComponent {
         <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>