add scroll service in app component

This commit is contained in:
X4Lo committed 2025-01-27 06:17:32 +01:00
1 parent cfbb77d447
commit 9342fb631b
1 file changed
+23 -1
+23 -1
View File
@@ -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<string, number>();
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', () => {