Skip to content

Commit

Permalink
fix(ui): fixed position calculation for infinite scrolling
Browse files Browse the repository at this point in the history
Previously we listened to the scroll event and calculated the position while the scrolling was taking place. This could lead to a buggy behaviour of the infinite scrolling list if the scroll-area was bigger than 400 px.
We added a debounce-timer to debounce the position calculation after the scroll is finished.

Closes: #153
  • Loading branch information
BastianGem authored and volkflo committed Aug 10, 2022
1 parent 5c04648 commit 0b0d524
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
mat-icon-button
aria-label="Clear"
color="primary"
(click)="fetchApis(true)">
(click)="resetSearch()">
<mat-icon>clear</mat-icon>
</button>
</mat-form-field>
Expand Down
7 changes: 6 additions & 1 deletion src/app/components/api-card-list/api-card-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ApiCardListComponent implements OnInit, OnDestroy {
*/
private initScrollEventListener() {
fromEvent(window, 'scroll')
.pipe(throttleTime(200))
.pipe(throttleTime(333), debounceTime(250))
.subscribe(() => {
const scrollPosition = window.scrollY;
const windowSize = window.innerHeight;
Expand All @@ -90,6 +90,11 @@ export class ApiCardListComponent implements OnInit, OnDestroy {
this.fetchApis(true);
}

public resetSearch() {
this.searchTerm = '';
this.fetchApis(true);
}

/**
* Fetches APIs from the backend, which will extend or reset the entire API list.
*
Expand Down

0 comments on commit 0b0d524

Please sign in to comment.