(commentCreated)="onCommentThreadCreated($event)"
></my-video-comment-add>
- <div class="comment-threads">
+ <div
+ class="comment-threads"
+ infiniteScroll
+ [infiniteScrollUpDistance]="1.5"
+ [infiniteScrollDistance]="0.5"
+ (scrolled)="onNearOfBottom()"
+ >
<div *ngFor="let comment of comments">
<my-video-comment
[comment]="comment"
sort: SortField = '-createdAt'
componentPagination: ComponentPagination = {
currentPage: 1,
- itemsPerPage: 25,
+ itemsPerPage: 10,
totalItems: null
}
inReplyToCommentId: number
) {}
ngOnInit () {
- this.videoCommentService.getVideoCommentThreads(this.video.id, this.componentPagination, this.sort)
- .subscribe(
- res => {
- this.comments = res.comments
- this.componentPagination.totalItems = res.totalComments
- },
-
- err => this.notificationsService.error('Error', err.message)
- )
+ this.loadMoreComments()
}
viewReplies (comment: VideoComment) {
)
}
+ loadMoreComments () {
+ this.videoCommentService.getVideoCommentThreads(this.video.id, this.componentPagination, this.sort)
+ .subscribe(
+ res => {
+ this.comments = this.comments.concat(res.comments)
+ this.componentPagination.totalItems = res.totalComments
+ },
+
+ err => this.notificationsService.error('Error', err.message)
+ )
+ }
+
onCommentThreadCreated (comment: VideoComment) {
this.comments.unshift(comment)
}
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
+
+ onNearOfBottom () {
+ this.componentPagination.currentPage++
+
+ if (this.hasMoreComments()) {
+ this.loadMoreComments()
+ }
+ }
+
+ protected hasMoreComments () {
+ // No results
+ if (this.componentPagination.totalItems === 0) return false
+
+ // Not loaded yet
+ if (!this.componentPagination.totalItems) return true
+
+ const maxPage = this.componentPagination.totalItems / this.componentPagination.itemsPerPage
+ return maxPage > this.componentPagination.currentPage
+ }
}