mirror of https://github.com/Chocobozzz/PeerTube
Add infinite scroll to comments
parent
80f8e364e1
commit
7416fbf335
|
@ -9,7 +9,13 @@
|
|||
(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"
|
||||
|
|
|
@ -22,7 +22,7 @@ export class VideoCommentsComponent implements OnInit {
|
|||
sort: SortField = '-createdAt'
|
||||
componentPagination: ComponentPagination = {
|
||||
currentPage: 1,
|
||||
itemsPerPage: 25,
|
||||
itemsPerPage: 10,
|
||||
totalItems: null
|
||||
}
|
||||
inReplyToCommentId: number
|
||||
|
@ -36,15 +36,7 @@ export class VideoCommentsComponent implements OnInit {
|
|||
) {}
|
||||
|
||||
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) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue