aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/infinite-scroller.directive.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video/infinite-scroller.directive.ts')
-rw-r--r--client/src/app/shared/video/infinite-scroller.directive.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/client/src/app/shared/video/infinite-scroller.directive.ts b/client/src/app/shared/video/infinite-scroller.directive.ts
index 4dc1f86e7..a02e9444a 100644
--- a/client/src/app/shared/video/infinite-scroller.directive.ts
+++ b/client/src/app/shared/video/infinite-scroller.directive.ts
@@ -6,10 +6,9 @@ import { fromEvent, Subscription } from 'rxjs'
6 selector: '[myInfiniteScroller]' 6 selector: '[myInfiniteScroller]'
7}) 7})
8export class InfiniteScrollerDirective implements OnInit, OnDestroy { 8export class InfiniteScrollerDirective implements OnInit, OnDestroy {
9 private static PAGE_VIEW_TOP_MARGIN = 500
10
11 @Input() containerHeight: number 9 @Input() containerHeight: number
12 @Input() pageHeight: number 10 @Input() pageHeight: number
11 @Input() firstLoadedPage = 1
13 @Input() percentLimit = 70 12 @Input() percentLimit = 70
14 @Input() autoInit = false 13 @Input() autoInit = false
15 14
@@ -23,6 +22,7 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
23 private scrollDownSub: Subscription 22 private scrollDownSub: Subscription
24 private scrollUpSub: Subscription 23 private scrollUpSub: Subscription
25 private pageChangeSub: Subscription 24 private pageChangeSub: Subscription
25 private middleScreen: number
26 26
27 constructor () { 27 constructor () {
28 this.decimalLimit = this.percentLimit / 100 28 this.decimalLimit = this.percentLimit / 100
@@ -39,6 +39,8 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
39 } 39 }
40 40
41 initialize () { 41 initialize () {
42 this.middleScreen = window.innerHeight / 2
43
42 // Emit the last value 44 // Emit the last value
43 const throttleOptions = { leading: true, trailing: true } 45 const throttleOptions = { leading: true, trailing: true }
44 46
@@ -92,6 +94,11 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
92 } 94 }
93 95
94 private calculateCurrentPage (current: number) { 96 private calculateCurrentPage (current: number) {
95 return Math.max(1, Math.round((current + InfiniteScrollerDirective.PAGE_VIEW_TOP_MARGIN) / this.pageHeight)) 97 const scrollY = current + this.middleScreen
98
99 const page = Math.max(1, Math.ceil(scrollY / this.pageHeight))
100
101 // Offset page
102 return page + (this.firstLoadedPage - 1)
96 } 103 }
97} 104}