|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { takeWhile } from 'rxjs/operators'; |
| 3 | +import { PageLoaderService } from '../page-loader.service'; |
| 4 | + |
| 5 | +@Component({ |
| 6 | + selector: 'app-page-loader', |
| 7 | + templateUrl: './page-loader.component.html', |
| 8 | + styleUrls: ['./page-loader.component.css'] |
| 9 | +}) |
| 10 | +export class PageLoaderComponent implements OnInit { |
| 11 | + |
| 12 | + constructor(private pageLoaderService: PageLoaderService) { } |
| 13 | + |
| 14 | + loading: boolean; |
| 15 | + message: string; |
| 16 | + progressValue: number; |
| 17 | + progressValueStyle: string; |
| 18 | + private _subscribed: boolean = true; |
| 19 | + |
| 20 | + ngOnInit(): void { |
| 21 | + this.subscribe(); |
| 22 | + } |
| 23 | + |
| 24 | + private subscribe() { |
| 25 | + this.pageLoaderService.state |
| 26 | + .pipe(takeWhile(() => this._subscribed)) |
| 27 | + .subscribe(loading => { |
| 28 | + this.loading = loading; |
| 29 | + }); |
| 30 | + this.pageLoaderService.message |
| 31 | + .pipe(takeWhile(() => this._subscribed)) |
| 32 | + .subscribe(message => { |
| 33 | + if (!!message) { |
| 34 | + this.message = message; |
| 35 | + } |
| 36 | + }); |
| 37 | + this.pageLoaderService.progressValue |
| 38 | + .pipe(takeWhile(() => this._subscribed)) |
| 39 | + .subscribe(progressValue => { |
| 40 | + if (!!progressValue) { |
| 41 | + this.progressValue = progressValue; |
| 42 | + this.progressValueStyle = `${progressValue}%`; |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
| 46 | + ngOnDestroy() { |
| 47 | + this._subscribed = false; |
| 48 | + } |
| 49 | + |
| 50 | +} |
0 commit comments