]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/comment/video-comments.component.ts
Fix changing video in watch page
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comments.component.ts
index 030dee9af05fc5e9afa503916fb3de22ef9a588b..6025256deccfbc8505858f3c812855a0d13a8363 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, Input, OnInit } from '@angular/core'
+import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'
 import { ConfirmService } from '@app/core'
 import { NotificationsService } from 'angular2-notifications'
 import { VideoComment as VideoCommentInterface, VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
@@ -15,7 +15,7 @@ import { VideoCommentService } from './video-comment.service'
   templateUrl: './video-comments.component.html',
   styleUrls: ['./video-comments.component.scss']
 })
-export class VideoCommentsComponent implements OnInit {
+export class VideoCommentsComponent implements OnChanges {
   @Input() video: VideoDetails
   @Input() user: User
 
@@ -37,9 +37,9 @@ export class VideoCommentsComponent implements OnInit {
     private videoCommentService: VideoCommentService
   ) {}
 
-  ngOnInit () {
-    if (this.video.commentsEnabled === true) {
-      this.loadMoreComments()
+  ngOnChanges (changes: SimpleChanges) {
+    if (changes['video']) {
+      this.loadVideoComments()
     }
   }
 
@@ -152,4 +152,21 @@ export class VideoCommentsComponent implements OnInit {
       this.deleteLocalCommentThread(commentChild, commentToDelete)
     }
   }
+
+  private loadVideoComments () {
+    if (this.video.commentsEnabled === true) {
+      // Reset all our fields
+      this.comments = []
+      this.threadComments = {}
+      this.threadLoading = {}
+      this.inReplyToCommentId = undefined
+      this.componentPagination = {
+        currentPage: 1,
+        itemsPerPage: 10,
+        totalItems: null
+      }
+
+      this.loadMoreComments()
+    }
+  }
 }