aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
diff options
context:
space:
mode:
authorkimsible <kimsible@users.noreply.github.com>2020-08-07 14:03:28 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-14 15:03:38 +0200
commitf63c03fb6ecccb5ac8e0d88917f072339b38ffb5 (patch)
tree37d9dc9fd18057e5071cfc7bba51177d02d8c094 /client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
parent09f8f73fbc8177930c76171300d4abc9f380d746 (diff)
downloadPeerTube-f63c03fb6ecccb5ac8e0d88917f072339b38ffb5.tar.gz
PeerTube-f63c03fb6ecccb5ac8e0d88917f072339b38ffb5.tar.zst
PeerTube-f63c03fb6ecccb5ac8e0d88917f072339b38ffb5.zip
Add delete & re-draft for comments without replies
Diffstat (limited to 'client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts')
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts30
1 files changed, 25 insertions, 5 deletions
diff --git a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
index d79efbb49..c1ddc0695 100644
--- a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
+++ b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
@@ -1,5 +1,5 @@
1import { Observable } from 'rxjs' 1import { Observable } from 'rxjs'
2import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' 2import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core'
3import { Router } from '@angular/router' 3import { Router } from '@angular/router'
4import { Notifier, User } from '@app/core' 4import { Notifier, User } from '@app/core'
5import { FormReactive, FormValidatorService, VideoCommentValidatorsService } from '@app/shared/shared-forms' 5import { FormReactive, FormValidatorService, VideoCommentValidatorsService } from '@app/shared/shared-forms'
@@ -13,12 +13,13 @@ import { VideoCommentCreate } from '@shared/models'
13 templateUrl: './video-comment-add.component.html', 13 templateUrl: './video-comment-add.component.html',
14 styleUrls: ['./video-comment-add.component.scss'] 14 styleUrls: ['./video-comment-add.component.scss']
15}) 15})
16export class VideoCommentAddComponent extends FormReactive implements OnInit { 16export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit {
17 @Input() user: User 17 @Input() user: User
18 @Input() video: Video 18 @Input() video: Video
19 @Input() parentComment: VideoComment 19 @Input() parentComment: VideoComment
20 @Input() parentComments: VideoComment[] 20 @Input() parentComments: VideoComment[]
21 @Input() focusOnInit = false 21 @Input() focusOnInit = false
22 @Input() textValue?: string
22 23
23 @Output() commentCreated = new EventEmitter<VideoComment>() 24 @Output() commentCreated = new EventEmitter<VideoComment>()
24 @Output() cancel = new EventEmitter() 25 @Output() cancel = new EventEmitter()
@@ -45,8 +46,9 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
45 }) 46 })
46 47
47 if (this.user) { 48 if (this.user) {
48 if (this.focusOnInit === true) { 49 if (this.textValue) {
49 this.textareaElement.nativeElement.focus() 50 this.patchTextValue(this.textValue, this.focusOnInit)
51 return
50 } 52 }
51 53
52 if (this.parentComment) { 54 if (this.parentComment) {
@@ -57,11 +59,17 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
57 const mentionsSet = new Set(mentions) 59 const mentionsSet = new Set(mentions)
58 const mentionsText = Array.from(mentionsSet).join(' ') + ' ' 60 const mentionsText = Array.from(mentionsSet).join(' ') + ' '
59 61
60 this.form.patchValue({ text: mentionsText }) 62 this.patchTextValue(mentionsText, this.focusOnInit)
61 } 63 }
62 } 64 }
63 } 65 }
64 66
67 ngOnChanges (changes: SimpleChanges) {
68 if (changes.textValue && changes.textValue.currentValue && changes.textValue.currentValue !== changes.textValue.previousValue) {
69 this.patchTextValue(changes.textValue.currentValue, true)
70 }
71 }
72
65 onValidKey () { 73 onValidKey () {
66 this.check() 74 this.check()
67 if (!this.form.valid) return 75 if (!this.form.valid) return
@@ -145,4 +153,16 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
145 return this.videoCommentService 153 return this.videoCommentService
146 .addCommentThread(this.video.id, commentCreate) 154 .addCommentThread(this.video.id, commentCreate)
147 } 155 }
156
157 private patchTextValue (text: string, focus: boolean) {
158 setTimeout(() => {
159 if (focus) {
160 this.textareaElement.nativeElement.focus()
161 }
162
163 this.textareaElement.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' })
164 })
165
166 this.form.patchValue({ text })
167 }
148} 168}