From e984372259cf53ecd2d33ad3e195bdf40567440c Mon Sep 17 00:00:00 2001 From: genja Date: Thu, 12 Nov 2026 21:58:55 +0100 Subject: [PATCH] =?UTF-8?q?made=20the=20"Zur=C3=BCck"=20button=20visible?= =?UTF-8?q?=20only=20within=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-searchbar.component.html | 25 +++-- .../app-searchbar/app-searchbar.component.ts | 97 ++++++++++++------- 2 files changed, 79 insertions(+), 43 deletions(-) diff --git a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html index 3f294de6..c5fd300c 100644 --- a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html +++ b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html @@ -3,24 +3,31 @@ - + @for (person of filteredPersons.results; track person.id) { - + {{ PERSON_ICON }} {{ person.display_name }} } + + @if (suggestionsLoading()) { + Suche läuft … + } @else if ( + searchControl.value && + searchControl.value.length >= 2 && + !filteredPersons.results?.length + ) { + Keine Personen gefunden + } diff --git a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts index bdd14b37..c3b7f791 100644 --- a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts +++ b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.ts @@ -1,4 +1,10 @@ -import { Component, inject, ViewChild, DestroyRef } from '@angular/core'; +import { + Component, + inject, + ViewChild, + DestroyRef, + signal, +} from '@angular/core'; import { MatIcon } from '@angular/material/icon'; import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { Router, ActivatedRoute } from '@angular/router'; @@ -11,9 +17,11 @@ import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; import { switchMap, debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { of } from 'rxjs'; +import { finalize, of } from 'rxjs'; import { PersonsService, AuthorsListResponse } from '../../../api'; import { PERSON_ICON, SEARCH_ICON } from '../icons'; +import { CredentialService } from '../../services/credential.service'; +import { activeInstitutionPersonListQueryParams } from '../../person-list-query-params'; @Component({ selector: 'app-searchbar', @@ -48,12 +56,13 @@ export class AppSearchbarComponent { private readonly router = inject(Router); private readonly route = inject(ActivatedRoute); private readonly personService = inject(PersonsService); - constructor() { - const route = inject(ActivatedRoute); - const router = inject(Router); + private readonly credentialService = inject(CredentialService); + readonly suggestionsLoading = signal(false); + + constructor() { // Sync searchControl from query param on every URL change - route.queryParams + this.route.queryParams .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe((params) => { const query = params['query'] ?? ''; @@ -67,13 +76,17 @@ export class AppSearchbarComponent { .pipe( debounceTime(300), distinctUntilChanged(), - switchMap((v) => { - const value = v ?? ''; - if (value.length < 2) return of(this.emptyPersons()); - return this.personService.searchPersonsAutocomplete( - value, - 'display_name', - ); + switchMap((value) => { + const term = (value ?? '').trim(); + if (term.length < 2) { + this.suggestionsLoading.set(false); + return of(this.emptyPersons()); + } + + this.suggestionsLoading.set(true); + return this.personService + .searchPersonsAutocomplete(term, 'display_name') + .pipe(finalize(() => this.suggestionsLoading.set(false))); }), takeUntilDestroyed(this.destroyRef), ) @@ -83,22 +96,23 @@ export class AppSearchbarComponent { } selectPerson(personName: string | undefined | null): void { - if (personName) { - this.searchControl.setValue(personName); - this.startSearch(); - } + if (!personName) return; + + this.searchControl.setValue(personName, { emitEvent: false }); + this.startSearch(); } - onKeydownTab(event: KeyboardEvent): void { + onEnter(event: Event): void { + if (event.defaultPrevented) return; + + // Let Material select the highlighted option; its optionSelected handler + // performs the navigation. Only free-text Enter starts a search here. + if (this.autocomplete?.isOpen && this.autocompleteTrigger?.activeOption) { + return; + } + event.preventDefault(); - const first = this.filteredPersons?.results?.[0]; - if (first?.display_name) { - this.searchControl.setValue(first.display_name); - } - } - - onEnter(): void { - this.autocompleteTrigger.closePanel(); + this.autocompleteTrigger?.closePanel(); this.startSearch(); } @@ -107,16 +121,31 @@ export class AppSearchbarComponent { } startSearch(): void { - const search = this.searchControl.value ?? ''; + const search = (this.searchControl.value ?? '').trim(); + const currentPath = this.router.url.split('?')[0]; + const onPersonList = currentPath.startsWith('/persons'); - this.router.navigate( - this.router.url.startsWith('/persons') ? [] : ['/persons'], - { - relativeTo: this.route, - queryParams: { query: search || null, page: 1 }, - queryParamsHandling: 'merge', + // On the person list, keep the active filters. Anywhere else, start from + // the account's institution defaults and never leak unrelated params + // (sort keys, titles, topics from other sections). + const baseParams: Record = onPersonList + ? { ...this.router.parseUrl(this.router.url).queryParams } + : activeInstitutionPersonListQueryParams( + this.credentialService.effectiveInstitutionId(), + this.credentialService.organizationName(), + ); + + delete baseParams['query']; + delete baseParams['page']; + + void this.router.navigate(['/persons'], { + queryParams: { + ...baseParams, + query: search || null, + page: 1, + pageSize: baseParams['pageSize'] ?? 10, }, - ); + }); } private emptyPersons(): AuthorsListResponse {