-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'
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
private videoCommentService: VideoCommentService
) {}
- ngOnInit () {
- if (this.video.commentsEnabled === true) {
- this.loadMoreComments()
+ ngOnChanges (changes: SimpleChanges) {
+ if (changes['video']) {
+ this.loadVideoComments()
}
}
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()
+ }
+ }
}