diff --git a/apps/red-ui/src/app/services/loading.service.ts b/apps/red-ui/src/app/services/loading.service.ts index c7839115d..0f8287988 100644 --- a/apps/red-ui/src/app/services/loading.service.ts +++ b/apps/red-ui/src/app/services/loading.service.ts @@ -1,11 +1,14 @@ import { EventEmitter, Injectable } from '@angular/core'; import { Observable } from 'rxjs'; +const MIN_LOADING_TIME = 300; + @Injectable({ providedIn: 'root' }) export class LoadingService { private readonly _loadingEvent = new EventEmitter(); + private _loadingStarted: number; get isLoading(): Observable { return this._loadingEvent; @@ -13,9 +16,18 @@ export class LoadingService { start(): void { this._loadingEvent.next(true); + this._loadingStarted = new Date().getTime(); } stop(): void { + const timeDelta = new Date().getTime() - this._loadingStarted; + if (timeDelta < MIN_LOADING_TIME) { + setTimeout(() => { + this._loadingEvent.next(false); + }, MIN_LOADING_TIME - timeDelta); + return; + } + this._loadingEvent.next(false); } }