This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { Component, inject, signal, DestroyRef } from '@angular/core';
|
||||
import { Router, RouterLink, ActivatedRoute } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { toObservable } from '@angular/core/rxjs-interop';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
@@ -15,7 +14,7 @@ import { MatButtonModule } from '@angular/material/button';
|
||||
import { CustomAuthor, PersonsSearchService } from '../../api';
|
||||
import { SharedStateService } from '../../shared/services/shared-state.service';
|
||||
import { PaginationService } from '../../shared/services/pagination.service';
|
||||
import { distinctUntilChanged, finalize } from 'rxjs';
|
||||
import { finalize } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person-list',
|
||||
@@ -76,23 +75,7 @@ export class PersonListComponent {
|
||||
bookmarkedIds = new Set<string>();
|
||||
|
||||
constructor() {
|
||||
// 1. Sync global topbar search to route parameters
|
||||
toObservable(this.state.searchValue)
|
||||
.pipe(
|
||||
distinctUntilChanged(),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
)
|
||||
.subscribe((val) => {
|
||||
const currentQuery = this.route.snapshot.queryParams['query'] || '';
|
||||
if (currentQuery !== (val || '')) {
|
||||
this.router.navigate([], {
|
||||
queryParams: { query: val || null, page: 1 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Subscribe to route query parameters to trigger searches
|
||||
// Subscribe to route query parameters to trigger searches
|
||||
this.route.queryParams
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((params) => {
|
||||
|
||||
@@ -67,12 +67,12 @@ export class AppLayoutComponent implements OnInit, OnDestroy {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
startSearch(){
|
||||
console.log("updated to", this.searchValue.value,this.router.url)
|
||||
|
||||
if (this.router.url.startsWith('/persons')) {
|
||||
this.router.navigate(['/persons']);
|
||||
}
|
||||
this.state.searchValue.set(this.searchValue.value);
|
||||
const query = this.searchValue.value || null;
|
||||
this.state.searchValue.set(query);
|
||||
this.router.navigate(['/persons'], {
|
||||
queryParams: { query, page: 1 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
navigateBack(){
|
||||
this.location.back()
|
||||
|
||||
Reference in New Issue
Block a user