Add loading indicator to orderedAsyncGuards
This commit is contained in:
parent
0885ad776d
commit
67485fdac2
@ -3,6 +3,7 @@ import { inject, Injectable, InjectionToken, Injector, runInInjectionContext } f
|
|||||||
import { concatMap, firstValueFrom, from, last, of, takeWhile } from 'rxjs';
|
import { concatMap, firstValueFrom, from, last, of, takeWhile } from 'rxjs';
|
||||||
import { LoadingService } from '../loading';
|
import { LoadingService } from '../loading';
|
||||||
import { SkeletonService } from './skeleton.service';
|
import { SkeletonService } from './skeleton.service';
|
||||||
|
import { tap } from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@ -68,8 +69,10 @@ export type AsyncGuard = (route: ActivatedRouteSnapshot, state: RouterStateSnaps
|
|||||||
export function orderedAsyncGuards(guards: Array<AsyncGuard>): CanActivateFn {
|
export function orderedAsyncGuards(guards: Array<AsyncGuard>): CanActivateFn {
|
||||||
return (route, state) => {
|
return (route, state) => {
|
||||||
const injector = inject(Injector);
|
const injector = inject(Injector);
|
||||||
|
const loadingService = inject(LoadingService);
|
||||||
|
|
||||||
return from(guards).pipe(
|
return from(guards).pipe(
|
||||||
|
tap(() => loadingService.start()),
|
||||||
// For each guard, fire canActivate and wait for it
|
// For each guard, fire canActivate and wait for it
|
||||||
// to complete.
|
// to complete.
|
||||||
concatMap(guard => runInInjectionContext(injector, () => guard(route, state))),
|
concatMap(guard => runInInjectionContext(injector, () => guard(route, state))),
|
||||||
@ -78,6 +81,7 @@ export function orderedAsyncGuards(guards: Array<AsyncGuard>): CanActivateFn {
|
|||||||
takeWhile(value => value === true, /* inclusive */ true),
|
takeWhile(value => value === true, /* inclusive */ true),
|
||||||
// Return the last guard's result.
|
// Return the last guard's result.
|
||||||
last(),
|
last(),
|
||||||
|
tap(() => loadingService.stop()),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user