mirror of
https://github.com/mempool/mempool.git
synced 2025-01-01 03:04:27 +01:00
33 lines
901 B
TypeScript
33 lines
901 B
TypeScript
import { ILoadingIndicators } from '../mempool.interfaces';
|
|
|
|
class LoadingIndicators {
|
|
private loadingIndicators: ILoadingIndicators = {
|
|
'mempool': 0,
|
|
};
|
|
private progressChangedCallback: ((loadingIndicators: ILoadingIndicators) => void) | undefined;
|
|
|
|
constructor() { }
|
|
|
|
public setProgressChangedCallback(fn: (loadingIndicators: ILoadingIndicators) => void) {
|
|
this.progressChangedCallback = fn;
|
|
}
|
|
|
|
public setProgress(name: string, progressPercent: number) {
|
|
const newProgress = Math.round(progressPercent);
|
|
if (newProgress >= 100) {
|
|
delete this.loadingIndicators[name];
|
|
} else {
|
|
this.loadingIndicators[name] = newProgress;
|
|
}
|
|
if (this.progressChangedCallback) {
|
|
this.progressChangedCallback(this.loadingIndicators);
|
|
}
|
|
}
|
|
|
|
public getLoadingIndicators() {
|
|
return this.loadingIndicators;
|
|
}
|
|
}
|
|
|
|
export default new LoadingIndicators();
|