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 ++++++++++++---------- .../comment/video-comment.component.html | 2 +- .../comment/video-comment.component.ts | 6 +++- .../comment/video-comments.component.html | 1 - .../comment/video-comments.component.ts | 4 +-- 5 files changed, 30 insertions(+), 24 deletions(-) (limited to 'client/src/app/+videos') 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) { diff --git a/client/src/app/+videos/+video-watch/comment/video-comment.component.html b/client/src/app/+videos/+video-watch/comment/video-comment.component.html index 8e44d0052..c4b2cd117 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comment.component.html +++ b/client/src/app/+videos/+video-watch/comment/video-comment.component.html @@ -1,4 +1,4 @@ -