import { HttpEvent, HttpInterceptorFn, HttpRequest, HttpHandlerFn } from "@angular/common/http"; import { inject } from "@angular/core"; import { Observable, finalize } from "rxjs"; import { LoaderService } from "../services/loader.service"; let totalRequests = 0; export const loadingInterceptor: HttpInterceptorFn = ( req: HttpRequest, next: HttpHandlerFn ): Observable> => { const loadingSvc = inject(LoaderService); if(req.url.includes('/RefreshToken')) { return next(req); } totalRequests++; loadingSvc.setLoading(true); return next(req).pipe( finalize(() => { totalRequests--; if (totalRequests === 0) { loadingSvc.setLoading(false); } }) ); };