From: Chocobozzz Date: Fri, 29 Dec 2017 08:29:32 +0000 (+0100) Subject: Add infinite scroll to comments X-Git-Tag: v0.0.1-alpha~68 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7416fbf3359fc0b890cba3dae9661fe450604b21;p=oweals%2Fpeertube.git Add infinite scroll to comments --- diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.html b/client/src/app/videos/+video-watch/comment/video-comments.component.html index 9d7581269..5c6908150 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.html @@ -9,7 +9,13 @@ (commentCreated)="onCommentThreadCreated($event)" > -
+
{ - this.comments = res.comments - this.componentPagination.totalItems = res.totalComments - }, - - err => this.notificationsService.error('Error', err.message) - ) + this.loadMoreComments() } viewReplies (comment: VideoComment) { @@ -61,6 +53,18 @@ export class VideoCommentsComponent implements OnInit { ) } + 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) } @@ -76,4 +80,23 @@ export class VideoCommentsComponent implements OnInit { 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 + } }