]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Small refactor comments
authorkimsible <kimsible@users.noreply.github.com>
Wed, 12 Aug 2020 10:43:26 +0000 (12:43 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Fri, 14 Aug 2020 13:03:38 +0000 (15:03 +0200)
client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
client/src/app/+videos/+video-watch/comment/video-comment.component.html
client/src/app/+videos/+video-watch/comment/video-comment.component.ts
client/src/app/+videos/+video-watch/comment/video-comments.component.html
client/src/app/+videos/+video-watch/comment/video-comments.component.ts

index 3d0611a2df6e6e36cc5e8e5919be6e931afeac2a..3fa5fd623af7a419549cdbfbe1f1c87da70966db 100644 (file)
@@ -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) {
index 8e44d005226830ac1b8b7c0ee164682fe6e3695b..c4b2cd1179e353548b410bdebcd5cc365e961f4c 100644 (file)
@@ -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
index 5491023ee5f6fd8e31a6c3b7f3d2d612cb3216fc..17e7e28ca449a39eb86ffbdc5fda301a64a6b704 100644 (file)
@@ -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
index ac69f094b1277df8df7b6264f3a2462c29c4e5d1..1bc0885a4d0c584cb46ea377058c7fc7b17d48e7 100644 (file)
@@ -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>
index 9e8e143c257e658856e4dcdfbaca2a12de324968..adce31c5bb52ea4cbd8f3f59e787c94089f29f01 100644 (file)
@@ -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) {