]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Prevent commenting twice
authorChocobozzz <me@florianbigard.com>
Mon, 18 Jun 2018 08:29:17 +0000 (10:29 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 18 Jun 2018 08:29:17 +0000 (10:29 +0200)
client/src/app/videos/+video-watch/comment/video-comment-add.component.ts

index 46d7a4e9eb6377114ebd523fa86536f86d8690fa..9998685e8fda24ebea4496b38a2aea7dc99b231c 100644 (file)
@@ -27,6 +27,8 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
 
   @ViewChild('textarea') private textareaElement: ElementRef
 
+  private addingComment = false
+
   constructor (
     protected formValidatorService: FormValidatorService,
     private videoCommentValidatorsService: VideoCommentValidatorsService,
@@ -66,6 +68,11 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
   }
 
   formValidated () {
+    // If we validate very quickly the comment form, we might comment twice
+    if (this.addingComment) return
+
+    this.addingComment = true
+
     const commentCreate: VideoCommentCreate = this.form.value
     let obs: Observable<any>
 
@@ -77,11 +84,16 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
 
     obs.subscribe(
       comment => {
+        this.addingComment = false
         this.commentCreated.emit(comment)
         this.form.reset()
       },
 
-      err => this.notificationsService.error(this.i18n('Error'), err.text)
+      err => {
+        this.addingComment = false
+
+        this.notificationsService.error(this.i18n('Error'), err.text)
+      }
     )
   }