feat: add progress bar (#66)
Add progress bar for loading data via http requests. Fixes #65
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Injectable, EventEmitter } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProgressBarService {
|
||||
|
||||
public updateProgressBar: EventEmitter<any>;
|
||||
private requestsRunning = 0;
|
||||
|
||||
constructor() {
|
||||
this.updateProgressBar = new EventEmitter();
|
||||
}
|
||||
|
||||
public getRequestsRunning(): number {
|
||||
return this.requestsRunning;
|
||||
}
|
||||
|
||||
public increase(): void {
|
||||
this.requestsRunning++;
|
||||
if (this.requestsRunning === 1) {
|
||||
this.updateProgressBar.emit('indeterminate');
|
||||
}
|
||||
}
|
||||
|
||||
public decrease(): void {
|
||||
if (this.requestsRunning > 0) {
|
||||
this.requestsRunning--;
|
||||
if (this.requestsRunning === 0) {
|
||||
this.updateProgressBar.emit('none');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user