diff options
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.ts | 30 |
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 @@ | |||
1 | import { Observable } from 'rxjs' | 1 | import { Observable } from 'rxjs' |
2 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | 2 | import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core' |
3 | import { Router } from '@angular/router' | 3 | import { Router } from '@angular/router' |
4 | import { Notifier, User } from '@app/core' | 4 | import { Notifier, User } from '@app/core' |
5 | import { FormReactive, FormValidatorService, VideoCommentValidatorsService } from '@app/shared/shared-forms' | 5 | import { 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 | }) |
16 | export class VideoCommentAddComponent extends FormReactive implements OnInit { | 16 | export 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 | } |