]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
Delete highlighted comment too if needed
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comment-add.component.ts
index c70e544a33417225619c4099afa088c55f59dcb3..9998685e8fda24ebea4496b38a2aea7dc99b231c 100644 (file)
@@ -3,13 +3,13 @@ import { NotificationsService } from 'angular2-notifications'
 import { Observable } from 'rxjs'
 import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model'
 import { FormReactive } from '../../../shared'
-import { VIDEO_COMMENT_TEXT } from '../../../shared/forms/form-validators/video-comment'
 import { User } from '../../../shared/users'
 import { Video } from '../../../shared/video/video.model'
 import { VideoComment } from './video-comment.model'
 import { VideoCommentService } from './video-comment.service'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
+import { VideoCommentValidatorsService } from '@app/shared/forms/form-validators/video-comment-validators.service'
 
 @Component({
   selector: 'my-video-comment-add',
@@ -27,8 +27,11 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
 
   @ViewChild('textarea') private textareaElement: ElementRef
 
+  private addingComment = false
+
   constructor (
     protected formValidatorService: FormValidatorService,
+    private videoCommentValidatorsService: VideoCommentValidatorsService,
     private notificationsService: NotificationsService,
     private videoCommentService: VideoCommentService,
     private i18n: I18n
@@ -38,7 +41,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
 
   ngOnInit () {
     this.buildForm({
-      text: VIDEO_COMMENT_TEXT
+      text: this.videoCommentValidatorsService.VIDEO_COMMENT_TEXT
     })
 
     if (this.focusOnInit === true) {
@@ -65,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>
 
@@ -76,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)
+      }
     )
   }