diff options
Diffstat (limited to 'client/src/app/shared/video/infinite-scroller.directive.ts')
-rw-r--r-- | client/src/app/shared/video/infinite-scroller.directive.ts | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/client/src/app/shared/video/infinite-scroller.directive.ts b/client/src/app/shared/video/infinite-scroller.directive.ts index e2730423f..0448e2c23 100644 --- a/client/src/app/shared/video/infinite-scroller.directive.ts +++ b/client/src/app/shared/video/infinite-scroller.directive.ts | |||
@@ -1,14 +1,6 @@ | |||
1 | import { distinct, distinctUntilChanged, filter, map, share, startWith, throttleTime } from 'rxjs/operators' | ||
1 | import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core' | 2 | import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core' |
2 | import 'rxjs/add/operator/debounceTime' | 3 | import { fromEvent, Subscription } from 'rxjs' |
3 | import 'rxjs/add/operator/distinct' | ||
4 | import 'rxjs/add/operator/distinctUntilChanged' | ||
5 | import 'rxjs/add/operator/filter' | ||
6 | import 'rxjs/add/operator/map' | ||
7 | import 'rxjs/add/operator/share' | ||
8 | import 'rxjs/add/operator/startWith' | ||
9 | import 'rxjs/add/operator/throttleTime' | ||
10 | import { fromEvent } from 'rxjs/observable/fromEvent' | ||
11 | import { Subscription } from 'rxjs/Subscription' | ||
12 | 4 | ||
13 | @Directive({ | 5 | @Directive({ |
14 | selector: '[myInfiniteScroller]' | 6 | selector: '[myInfiniteScroller]' |
@@ -51,43 +43,51 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy { | |||
51 | const throttleOptions = { leading: true, trailing: true } | 43 | const throttleOptions = { leading: true, trailing: true } |
52 | 44 | ||
53 | const scrollObservable = fromEvent(window, 'scroll') | 45 | const scrollObservable = fromEvent(window, 'scroll') |
54 | .startWith(true) | 46 | .pipe( |
55 | .throttleTime(200, undefined, throttleOptions) | 47 | startWith(null), |
56 | .map(() => ({ current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight })) | 48 | throttleTime(200, undefined, throttleOptions), |
57 | .distinctUntilChanged((o1, o2) => o1.current === o2.current) | 49 | map(() => ({ current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight })), |
58 | .share() | 50 | distinctUntilChanged((o1, o2) => o1.current === o2.current), |
51 | share() | ||
52 | ) | ||
59 | 53 | ||
60 | // Scroll Down | 54 | // Scroll Down |
61 | this.scrollDownSub = scrollObservable | 55 | this.scrollDownSub = scrollObservable |
62 | // Check we scroll down | 56 | .pipe( |
63 | .filter(({ current }) => { | 57 | // Check we scroll down |
64 | const res = this.lastCurrentBottom < current | 58 | filter(({ current }) => { |
59 | const res = this.lastCurrentBottom < current | ||
65 | 60 | ||
66 | this.lastCurrentBottom = current | 61 | this.lastCurrentBottom = current |
67 | return res | 62 | return res |
68 | }) | 63 | }), |
69 | .filter(({ current, maximumScroll }) => maximumScroll <= 0 || (current / maximumScroll) > this.decimalLimit) | 64 | filter(({ current, maximumScroll }) => maximumScroll <= 0 || (current / maximumScroll) > this.decimalLimit) |
65 | ) | ||
70 | .subscribe(() => this.nearOfBottom.emit()) | 66 | .subscribe(() => this.nearOfBottom.emit()) |
71 | 67 | ||
72 | // Scroll up | 68 | // Scroll up |
73 | this.scrollUpSub = scrollObservable | 69 | this.scrollUpSub = scrollObservable |
74 | // Check we scroll up | 70 | .pipe( |
75 | .filter(({ current }) => { | 71 | // Check we scroll up |
76 | const res = this.lastCurrentTop > current | 72 | filter(({ current }) => { |
73 | const res = this.lastCurrentTop > current | ||
77 | 74 | ||
78 | this.lastCurrentTop = current | 75 | this.lastCurrentTop = current |
79 | return res | 76 | return res |
80 | }) | 77 | }), |
81 | .filter(({ current, maximumScroll }) => { | 78 | filter(({ current, maximumScroll }) => { |
82 | return current !== 0 && (1 - (current / maximumScroll)) > this.decimalLimit | 79 | return current !== 0 && (1 - (current / maximumScroll)) > this.decimalLimit |
83 | }) | 80 | }) |
81 | ) | ||
84 | .subscribe(() => this.nearOfTop.emit()) | 82 | .subscribe(() => this.nearOfTop.emit()) |
85 | 83 | ||
86 | // Page change | 84 | // Page change |
87 | this.pageChangeSub = scrollObservable | 85 | this.pageChangeSub = scrollObservable |
88 | .distinct() | 86 | .pipe( |
89 | .map(({ current }) => this.calculateCurrentPage(current)) | 87 | distinct(), |
90 | .distinctUntilChanged() | 88 | map(({ current }) => this.calculateCurrentPage(current)), |
89 | distinctUntilChanged() | ||
90 | ) | ||
91 | .subscribe(res => this.pageChanged.emit(res)) | 91 | .subscribe(res => this.pageChanged.emit(res)) |
92 | } | 92 | } |
93 | 93 | ||