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 {
|
export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit {
|
||||||
@Input() user: User
|
@Input() user: User
|
||||||
@Input() video: Video
|
@Input() video: Video
|
||||||
@Input() parentComment: VideoComment
|
@Input() parentComment?: VideoComment
|
||||||
@Input() parentComments: VideoComment[]
|
@Input() parentComments?: VideoComment[]
|
||||||
@Input() focusOnInit = false
|
@Input() focusOnInit = false
|
||||||
@Input() textValue?: string
|
@Input() textValue?: string
|
||||||
@Input() commentThread?: boolean
|
|
||||||
|
|
||||||
@Output() commentCreated = new EventEmitter<VideoComment>()
|
@Output() commentCreated = new EventEmitter<VideoComment>()
|
||||||
@Output() cancel = new EventEmitter()
|
@Output() cancel = new EventEmitter()
|
||||||
|
@ -57,27 +56,13 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.user) {
|
if (this.user) {
|
||||||
if (this.commentThread) {
|
if (!this.parentComment) {
|
||||||
this.addingCommentButtonValue = this.i18n('Comment')
|
this.addingCommentButtonValue = this.i18n('Comment')
|
||||||
} else {
|
} else {
|
||||||
this.addingCommentButtonValue = this.i18n('Reply')
|
this.addingCommentButtonValue = this.i18n('Reply')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.textValue) {
|
this.initTextValue()
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +161,24 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
|
||||||
.addCommentThread(this.video.id, commentCreate)
|
.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) {
|
private patchTextValue (text: string, focus: boolean) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (focus) {
|
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">
|
<div class="left">
|
||||||
<a *ngIf="!comment.isDeleted" [href]="comment.account.url" target="_blank" rel="noopener noreferrer">
|
<a *ngIf="!comment.isDeleted" [href]="comment.account.url" target="_blank" rel="noopener noreferrer">
|
||||||
<img
|
<img
|
||||||
|
|
|
@ -75,7 +75,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
this.resetReply.emit()
|
this.resetReply.emit()
|
||||||
|
|
||||||
delete this.redraftValue
|
this.redraftValue = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
onWantToReply (comment?: VideoComment) {
|
onWantToReply (comment?: VideoComment) {
|
||||||
|
@ -133,6 +133,10 @@ export class VideoCommentComponent implements OnInit, OnChanges {
|
||||||
($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
|
($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) {
|
private getUserIfNeeded (account: Account) {
|
||||||
if (!account.userId) return
|
if (!account.userId) return
|
||||||
if (!this.authService.isLoggedIn()) return
|
if (!this.authService.isLoggedIn()) return
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
[user]="user"
|
[user]="user"
|
||||||
(commentCreated)="onCommentThreadCreated($event)"
|
(commentCreated)="onCommentThreadCreated($event)"
|
||||||
[textValue]="commentThreadRedraftValue"
|
[textValue]="commentThreadRedraftValue"
|
||||||
[commentThread]="true"
|
|
||||||
></my-video-comment-add>
|
></my-video-comment-add>
|
||||||
|
|
||||||
<div *ngIf="componentPagination.totalItems === 0 && comments.length === 0" i18n>No comments.</div>
|
<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) {
|
onCommentThreadCreated (comment: VideoComment) {
|
||||||
this.comments.unshift(comment)
|
this.comments.unshift(comment)
|
||||||
delete this.commentThreadRedraftValue
|
this.commentThreadRedraftValue = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
onWantedToReply (comment: VideoComment) {
|
onWantedToReply (comment: VideoComment) {
|
||||||
|
@ -142,7 +142,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
|
|
||||||
onResetReply () {
|
onResetReply () {
|
||||||
this.inReplyToCommentId = undefined
|
this.inReplyToCommentId = undefined
|
||||||
delete this.commentReplyRedraftValue
|
this.commentReplyRedraftValue = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
onThreadCreated (commentTree: VideoCommentThreadTree) {
|
onThreadCreated (commentTree: VideoCommentThreadTree) {
|
||||||
|
|
Loading…
Reference in New Issue