diff --git a/webapp/src/app/shared/services/resolver-state.service.ts b/webapp/src/app/shared/services/resolver-state.service.ts new file mode 100644 index 00000000..89c92405 --- /dev/null +++ b/webapp/src/app/shared/services/resolver-state.service.ts @@ -0,0 +1,41 @@ +import { Injectable, signal, inject, computed } from '@angular/core'; +import { Router, RouterEvent, ActivatedRoute } from '@angular/router'; +import { toSignal } from '@angular/core/rxjs-interop'; +import { ResolveEnd, ResolveStart } from '@angular/router'; +import { + NavigationEnd, + NavigationError, + NavigationCancel, +} from '@angular/router'; +@Injectable({ providedIn: 'root' }) +export class ResolverStateService { + private readonly router = inject(Router); + + readonly resolvingUrl = signal(null); + readonly previousUrl = signal(null); + + readonly isResolving = computed(() => this.resolvingUrl() !== null); + readonly isResolvingPersonsFromOutside = computed(() => { + const from = this.previousUrl(); + const to = this.resolvingUrl(); + if (!to?.startsWith('/persons')) return false; + return !from?.startsWith('/persons'); // came from outside + }); + + constructor() { + this.router.events.subscribe(event => { + if (event instanceof ResolveStart) { + this.previousUrl.set(this.router.url); // capture current before it changes + this.resolvingUrl.set(event.url); + } + + if ( + event instanceof NavigationEnd || + event instanceof NavigationCancel || + event instanceof NavigationError + ) { + this.resolvingUrl.set(null); + } + }); + } +} \ No newline at end of file diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.html b/webapp/src/app/shared/ui/app-layout/app-layout.component.html index ef8b9baa..61c854bf 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.html +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.html @@ -41,7 +41,12 @@
- + @if (resolverState.isResolvingPersonsFromOutside()) { + + } @else { + + } +
diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts index 45987649..39205fb0 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts @@ -4,6 +4,7 @@ import { OnDestroy, OnInit, ViewChild, + inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MatToolbarModule } from '@angular/material/toolbar'; @@ -17,10 +18,11 @@ import { MatTooltipModule } from '@angular/material/tooltip'; import { CredentialService } from '../../services/credential.service'; import { Location } from '@angular/common'; import { AppSearchbarComponent } from "../app-searchbar/app-searchbar.component"; - +import { ResolverStateService } from '../../services/resolver-state.service'; +import { LoadingComponent } from "../loading/loading.component"; @Component({ selector: 'app-layout', - imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, AppMenuComponent, MatTooltipModule, AppSearchbarComponent], + imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, AppMenuComponent, MatTooltipModule, AppSearchbarComponent, LoadingComponent], templateUrl: './app-layout.component.html', styleUrl: './app-layout.component.scss', standalone: true, @@ -30,7 +32,7 @@ export class AppLayoutComponent implements OnInit, OnDestroy { drawer?: MatDrawer; mediaQuery: MediaQueryList; - + protected resolverState = inject(ResolverStateService) mediaQueryListener: () => void; sideNavOpen = false; diff --git a/webapp/src/app/shared/ui/loading/loading.component.html b/webapp/src/app/shared/ui/loading/loading.component.html new file mode 100644 index 00000000..e65e0384 --- /dev/null +++ b/webapp/src/app/shared/ui/loading/loading.component.html @@ -0,0 +1,9 @@ +
+
+ + + {{icon}} + +
+ {{text}} +
\ No newline at end of file diff --git a/webapp/src/app/shared/ui/loading/loading.component.scss b/webapp/src/app/shared/ui/loading/loading.component.scss new file mode 100644 index 00000000..a88249cc --- /dev/null +++ b/webapp/src/app/shared/ui/loading/loading.component.scss @@ -0,0 +1,41 @@ + +.loading-container { + display: flex; + flex-direction: column; + align-items: center; + gap: 16px; + padding: 48px 0; +} + +.spinner-container { + --spinner-size: 60px; + + position: relative; + width: var(--spinner-size); + height: var(--spinner-size); +} + +.spinner-icon { + position: absolute; + inset: 0; + margin: auto; + + font-size: calc(var(--spinner-size) * 0.4); + width: calc(var(--spinner-size) * 0.4); + height: calc(var(--spinner-size) * 0.4); + + animation: pulse 1.2s ease-in-out infinite; +} + +@keyframes pulse { + 0%, + 100% { + transform: scale(1); + opacity: 1; + } + + 50% { + transform: scale(1.2); + opacity: 0.7; + } +} diff --git a/webapp/src/app/shared/ui/loading/loading.component.ts b/webapp/src/app/shared/ui/loading/loading.component.ts new file mode 100644 index 00000000..5f75a46a --- /dev/null +++ b/webapp/src/app/shared/ui/loading/loading.component.ts @@ -0,0 +1,15 @@ +import { Component,Input } from '@angular/core'; +import { MatProgressSpinner } from '@angular/material/progress-spinner'; +import { MatIcon } from '@angular/material/icon'; +@Component({ + selector: 'app-loading', + imports: [MatProgressSpinner,MatIcon], + templateUrl: './loading.component.html', + styleUrl: './loading.component.scss', +}) +export class LoadingComponent { +@Input() text = "Laden..." +@Input() icon = "graph_3"; +@Input() size = "150"; +@Input() diameter = "150"; +}