Skip to content

Commit

Permalink
Refine Feature Flags Root Table Pagination on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
zackcl committed Oct 4, 2024
1 parent fee28b8 commit 3c6c117
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div scroll (wheel)="fetchFlagsOnScroll()" class="flag-list-table-container" #tableContainer>
<div class="flag-list-table-container" #tableContainer>
<mat-progress-bar class="spinner" mode="indeterminate" *ngIf="isLoading$ | async"></mat-progress-bar>
<table
class="flag-list-table"
Expand Down Expand Up @@ -111,4 +111,5 @@
</td>
</tr>
</table>
<div #bottomTrigger></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,48 @@ export class FeatureFlagRootSectionCardTableComponent implements OnInit {

@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild('tableContainer') tableContainer: ElementRef;
@ViewChild('bottomTrigger') bottomTrigger: ElementRef;

private observer: IntersectionObserver;

constructor(private featureFlagsService: FeatureFlagsService) {}

ngOnInit() {
this.sortTable();
}

ngAfterViewInit() {
this.setupIntersectionObserver();
}

ngOnChanges() {
this.sortTable();
}

ngOnDestroy() {
if (this.observer) {
this.observer.disconnect();
}
}

private setupIntersectionObserver() {
const options = {
root: this.tableContainer.nativeElement,
rootMargin: '100px',
threshold: 0.1,
};

this.observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
this.fetchFlagsOnScroll();
}
}, options);

if (this.bottomTrigger) {
this.observer.observe(this.bottomTrigger.nativeElement);
}
}

private sortTable() {
if (this.dataSource$?.data) {
this.dataSource$.sortingDataAccessor = (item, property) =>
Expand Down

0 comments on commit 3c6c117

Please sign in to comment.