From 1b852f5fb705eeeaf7f0c5ebb1265a9dbc22d192 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Thu, 1 Aug 2019 10:25:31 +0300 Subject: [PATCH] feature(theme-shared): add route subscription to loader-bar.component --- .../loader-bar/loader-bar.component.ts | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts index 7ab7d2935e..a76e051db2 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts @@ -1,7 +1,9 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit, Input, OnDestroy } from '@angular/core'; import { Actions, ofActionSuccessful } from '@ngxs/store'; import { LoaderStart, LoaderStop } from '@abp/ng.core'; import { filter } from 'rxjs/operators'; +import { Router, NavigationStart, NavigationEnd } from '@angular/router'; +import { takeUntilDestroy } from '@ngx-validate/core'; @Component({ selector: 'abp-loader-bar', @@ -12,7 +14,7 @@ import { filter } from 'rxjs/operators'; `, styleUrls: ['./loader-bar.component.scss'], }) -export class LoaderBarComponent { +export class LoaderBarComponent implements OnDestroy { @Input() containerClass: string = 'abp-loader-bar'; @@ -29,21 +31,31 @@ export class LoaderBarComponent { interval: any; - constructor(private actions: Actions) { + constructor(private actions: Actions, private router: Router) { actions .pipe( ofActionSuccessful(LoaderStart, LoaderStop), filter(this.filter), + takeUntilDestroy(this), ) .subscribe(action => { - if (action instanceof LoaderStart) { - this.startLoading(); - } else { - this.stopLoading(); - } + if (action instanceof LoaderStart) this.startLoading(); + else this.stopLoading(); + }); + + router.events + .pipe( + filter(event => event instanceof NavigationStart || event instanceof NavigationEnd), + takeUntilDestroy(this), + ) + .subscribe(event => { + if (event instanceof NavigationStart) this.startLoading(); + else this.stopLoading(); }); } + ngOnDestroy() {} + startLoading() { this.isLoading = true; const interval = setInterval(() => {