1
0
mirror of https://github.com/google/nomulus synced 2026-02-10 06:50:30 +00:00
Files
nomulus/console-webapp/src/app/shared/services/globalLoader.service.ts
Pavlo Tkach 1929654f8c Replace less with scss, add homepage widgets, add registrars selector and registrars page (#2114)
* Replace less compiler with scss

* Replace less with scss, add homepage widgets, add registrars selector and registrars page
2023-09-01 11:48:30 -04:00

61 lines
1.8 KiB
TypeScript

// Copyright 2023 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Injectable } from '@angular/core';
import { Observable, Subscription, timeout } from 'rxjs';
export interface GlobalLoader {
loadingTimeout: () => void;
}
/**
* This class responsible for global application loading indicator
*
* <p>Only to be used for when the activity should indicate that the entire application is busy
* For instance - when initial user information is loading, which is crucial for any subsequent
* interaction with the application
*/
@Injectable({
providedIn: 'root',
})
export class GlobalLoaderService {
private static readonly TIMEOUT_MS = 3000;
private loaders = new Map<GlobalLoader, Subscription>();
public isLoading: boolean = false;
private syncLoading() {
this.isLoading = this.loaders.size > 0;
}
startGlobalLoader(c: GlobalLoader) {
const subscription = new Observable(() => {})
.pipe(timeout(GlobalLoaderService.TIMEOUT_MS))
.subscribe({
error: () => {
this.loaders.delete(c);
c.loadingTimeout();
this.syncLoading();
},
});
this.loaders.set(c, subscription);
this.syncLoading();
}
stopGlobalLoader(c: GlobalLoader) {
this.loaders.get(c)?.unsubscribe();
this.loaders.delete(c);
this.syncLoading();
}
}