Fixed infinite scrolling.
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
.search-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.results-box {
|
||||
background: #5757576c;
|
||||
display: flex;
|
||||
|
@ -45,22 +45,35 @@ export class AddNewPageComponent implements OnDestroy {
|
||||
),
|
||||
filters: this.filters,
|
||||
page: this.page.pipe(
|
||||
throttleTime(3000, undefined, { leading: true, trailing: true }),
|
||||
throttleTime(1500, undefined, { leading: true, trailing: true }),
|
||||
),
|
||||
}).pipe(
|
||||
filter(entry => !this.endOfResults() && entry.search!.length > 1),
|
||||
filter(entry => entry.search!.length > 1),
|
||||
throttleTime(1000, undefined, { leading: false, trailing: true }),
|
||||
scan((acc, next) => {
|
||||
// New searches means resetting to page 0.
|
||||
if (acc.search != next.search) {
|
||||
this.results = [];
|
||||
return {
|
||||
...next,
|
||||
page: 0
|
||||
page: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Keep searching the same page until error stops.
|
||||
if (this.searchError() != null) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
// Ignore further searching on the same search term.
|
||||
if (this.endOfResults()) {
|
||||
return {
|
||||
...next,
|
||||
page: -1,
|
||||
};
|
||||
}
|
||||
|
||||
// Next page.
|
||||
return {
|
||||
...next,
|
||||
page: Math.min(acc.page + 1, next.page),
|
||||
@ -117,7 +130,7 @@ export class AddNewPageComponent implements OnDestroy {
|
||||
// Prevent page changes when:
|
||||
// - new search is happening (emptying results);
|
||||
// - still scrolling through current content.
|
||||
if (scroll.scrollTop == 0 || scroll.scrollTop < limit) {
|
||||
if (scroll.scrollTop == 0 || scroll.scrollTop < limit - 25) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user