Small refactor comments
This commit is contained in:
parent
e548a7c9b0
commit
fdd1296521
|
@ -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<VideoComment>()
|
||||
@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) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div *ngIf="!comment.isDeleted || comment.isDeleted && comment.totalReplies !== 0" class="root-comment">
|
||||
<div *ngIf="isNotDeletedOrDeletedWithReplies()" class="root-comment">
|
||||
<div class="left">
|
||||
<a *ngIf="!comment.isDeleted" [href]="comment.account.url" target="_blank" rel="noopener noreferrer">
|
||||
<img
|
||||
|
|
|
@ -75,7 +75,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
|
|||
|
||||
this.resetReply.emit()
|
||||
|
||||
delete this.redraftValue
|
||||
this.redraftValue = undefined
|
||||
}
|
||||
|
||||
onWantToReply (comment?: VideoComment) {
|
||||
|
@ -133,6 +133,10 @@ export class VideoCommentComponent implements OnInit, OnChanges {
|
|||
($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
|
||||
}
|
||||
|
||||
isNotDeletedOrDeletedWithReplies () {
|
||||
return !this.comment.isDeleted || this.comment.isDeleted && this.comment.totalReplies !== 0
|
||||
}
|
||||
|
||||
private getUserIfNeeded (account: Account) {
|
||||
if (!account.userId) return
|
||||
if (!this.authService.isLoggedIn()) return
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
[user]="user"
|
||||
(commentCreated)="onCommentThreadCreated($event)"
|
||||
[textValue]="commentThreadRedraftValue"
|
||||
[commentThread]="true"
|
||||
></my-video-comment-add>
|
||||
|
||||
<div *ngIf="componentPagination.totalItems === 0 && comments.length === 0" i18n>No comments.</div>
|
||||
|
|
|
@ -133,7 +133,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
|
|||
|
||||
onCommentThreadCreated (comment: VideoComment) {
|
||||
this.comments.unshift(comment)
|
||||
delete this.commentThreadRedraftValue
|
||||
this.commentThreadRedraftValue = undefined
|
||||
}
|
||||
|
||||
onWantedToReply (comment: VideoComment) {
|
||||
|
@ -142,7 +142,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
|
|||
|
||||
onResetReply () {
|
||||
this.inReplyToCommentId = undefined
|
||||
delete this.commentReplyRedraftValue
|
||||
this.commentReplyRedraftValue = undefined
|
||||
}
|
||||
|
||||
onThreadCreated (commentTree: VideoCommentThreadTree) {
|
||||
|
|
Loading…
Reference in New Issue