diff --git a/frontend/src/app/shared/spinner/spinner.component.ts b/frontend/src/app/shared/spinner/spinner.component.ts
index b7d68e998..0933e42da 100644
--- a/frontend/src/app/shared/spinner/spinner.component.ts
+++ b/frontend/src/app/shared/spinner/spinner.component.ts
@@ -1,23 +1,20 @@
-import { AsyncPipe } from '@angular/common';
import { inject } from '@angular/core';
import { ChangeDetectionStrategy } from '@angular/core';
import { Component } from '@angular/core';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
-import { debounceTime } from 'rxjs/operators';
import { SpinnerService } from './spinner.service';
@Component({
selector: 'kpn-spinner',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
- @if (showSpinner$ | async) {
+ @if (service.showSpinner()) {
}
`,
standalone: true,
- imports: [MatProgressSpinnerModule, AsyncPipe],
+ imports: [MatProgressSpinnerModule],
})
export class SpinnerComponent {
- private readonly spinnerService = inject(SpinnerService);
- protected readonly showSpinner$ = this.spinnerService.spinnerState$.pipe(debounceTime(300));
+ protected readonly service = inject(SpinnerService);
}
diff --git a/frontend/src/app/shared/spinner/spinner.service.ts b/frontend/src/app/shared/spinner/spinner.service.ts
index f4547f84c..06f946324 100644
--- a/frontend/src/app/shared/spinner/spinner.service.ts
+++ b/frontend/src/app/shared/spinner/spinner.service.ts
@@ -1,9 +1,11 @@
import { Injectable } from '@angular/core';
+import { toSignal } from '@angular/core/rxjs-interop';
import { List } from 'immutable';
import { finalize } from 'rxjs';
import { of } from 'rxjs';
import { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
+import { debounceTime } from 'rxjs/operators';
import { concatMap } from 'rxjs/operators';
import { tap } from 'rxjs/operators';
@@ -11,13 +13,9 @@ import { tap } from 'rxjs/operators';
providedIn: 'root',
})
export class SpinnerService {
- readonly spinnerState$: Observable;
- private readonly _spinnerState$ = new BehaviorSubject(false);
private activeActions: List = List();
-
- constructor() {
- this.spinnerState$ = this._spinnerState$.asObservable();
- }
+ private readonly _spinnerState$ = new BehaviorSubject(false);
+ readonly showSpinner = toSignal(this._spinnerState$.pipe(debounceTime(300)));
showUntilCompleted(obs$: Observable, action: string): Observable {
return of(null).pipe(
@@ -32,7 +30,6 @@ export class SpinnerService {
if (this._spinnerState$.value !== true) {
this._spinnerState$.next(true);
}
- // console.log(`spinner start ${action} - activeActions = ${this.activeActions}, spinnerState=${this._spinnerState}`);
}
end(action: string): void {
@@ -40,6 +37,5 @@ export class SpinnerService {
if (this.activeActions.isEmpty() && this._spinnerState$.value !== false) {
this._spinnerState$.next(false);
}
- // console.log(`spinner end ${action} - activeActions = ${this.activeActions}, spinnerState=${this._spinnerState}`);
}
}