From 9342fb631b5405e48fd47ac1f9d003d1c5b9a124 Mon Sep 17 00:00:00 2001 From: X4Lo Date: Mon, 27 Jan 2025 06:17:32 +0100 Subject: [PATCH] add scroll service in app component --- frontend/src/app/app.component.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 9b4bb32..242909e 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -10,6 +10,7 @@ import { filter } from 'rxjs'; import PerfectScrollbar from 'perfect-scrollbar'; import { PingService } from './core/services/ping.service'; +import { ScrollService } from './core/services/scroll.service'; declare const window: any; @Component({ @@ -26,10 +27,19 @@ export class AppComponent implements OnInit, AfterViewInit { private scrollPositions = new Map(); private isBackNavigation = ''; - constructor(private router: Router, private pingService: PingService) {} + constructor( + private router: Router, + private pingService: PingService, + private scrollService: ScrollService + ) {} ngAfterViewInit() { this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement); + // Listen for the scroll event + this.scrollContainer.nativeElement.addEventListener( + 'ps-scroll-y', + this.onScroll.bind(this) + ); // this.router.events // .pipe(filter(event => event instanceof NavigationEnd)) @@ -71,6 +81,18 @@ export class AppComponent implements OnInit, AfterViewInit { this.checkBackendAvailability(); } + onScroll(): void { + const container = this.scrollContainer.nativeElement; + + // Check if the scrollbar is near the bottom + if ( + container.scrollTop + container.clientHeight >= + container.scrollHeight - 50 // Adjust the offset if necessary + ) { + this.scrollService.notifyScrollEnd(); + } + } + checkBackendAvailability() { if (window && window.electron && window.electron.ipcRenderer) { window.electron.ipcRenderer.on('backend-ready', () => {