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