Fixed infinite scrolling.

This commit is contained in:
Tom
2025-06-25 00:37:27 +00:00
parent e20231639c
commit 3326b7c589
2 changed files with 23 additions and 4 deletions

View File

@ -1,3 +1,9 @@
.search-content {
display: flex;
flex-direction: column;
height: 100vh;
}
.results-box {
background: #5757576c;
display: flex;

View File

@ -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;
}