From fdd1296521354401e9927e5faeb0aa17ba810c41 Mon Sep 17 00:00:00 2001 From: kimsible Date: Wed, 12 Aug 2020 12:43:26 +0200 Subject: Small refactor comments --- .../comment/video-comment-add.component.ts | 41 ++++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts') 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 3d0611a2d..3fa5fd623 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 @@ -17,11 +17,10 @@ import { I18n } from '@ngx-translate/i18n-polyfill' export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit { @Input() user: User @Input() video: Video - @Input() parentComment: VideoComment - @Input() parentComments: VideoComment[] + @Input() parentComment?: VideoComment + @Input() parentComments?: VideoComment[] @Input() focusOnInit = false @Input() textValue?: string - @Input() commentThread?: boolean @Output() commentCreated = new EventEmitter() @Output() cancel = new EventEmitter() @@ -57,27 +56,13 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, }) if (this.user) { - if (this.commentThread) { + if (!this.parentComment) { this.addingCommentButtonValue = this.i18n('Comment') } else { this.addingCommentButtonValue = this.i18n('Reply') } - if (this.textValue) { - this.patchTextValue(this.textValue, this.focusOnInit) - return - } - - if (this.parentComment) { - const mentions = this.parentComments - .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves - .map(c => '@' + c.by) - - const mentionsSet = new Set(mentions) - const mentionsText = Array.from(mentionsSet).join(' ') + ' ' - - this.patchTextValue(mentionsText, this.focusOnInit) - } + this.initTextValue() } } @@ -176,6 +161,24 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, .addCommentThread(this.video.id, commentCreate) } + private initTextValue () { + if (this.textValue) { + this.patchTextValue(this.textValue, this.focusOnInit) + return + } + + if (this.parentComment) { + const mentions = this.parentComments + .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves + .map(c => '@' + c.by) + + const mentionsSet = new Set(mentions) + const mentionsText = Array.from(mentionsSet).join(' ') + ' ' + + this.patchTextValue(mentionsText, this.focusOnInit) + } + } + private patchTextValue (text: string, focus: boolean) { setTimeout(() => { if (focus) { -- cgit v1.2.3