Skip to content

Commit

Permalink
review(fuzzy-search): get currentSearchFilters asynchronously when ne…
Browse files Browse the repository at this point in the history
…eded
  • Loading branch information
tkohr committed Feb 29, 2024
1 parent 8f74446 commit d94ca4a
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
AutocompleteComponent,
AutocompleteItem,
} from '@geonetwork-ui/ui/inputs'
import { Observable } from 'rxjs'
import { map, tap } from 'rxjs/operators'
import { Observable, firstValueFrom } from 'rxjs'
import { map } from 'rxjs/operators'
import { SearchFacade } from '../state/search.facade'
import { SearchService } from '../utils/service/search.service'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
Expand All @@ -31,7 +31,6 @@ export class FuzzySearchComponent implements OnInit {
@Output() itemSelected = new EventEmitter<CatalogRecord>()
@Output() inputSubmitted = new EventEmitter<string>()
searchInputValue$: Observable<{ title: string }>
currentSearchFilters: SearchFilters

displayWithFn: (record: CatalogRecord) => string = (record) => record?.title

Expand All @@ -48,7 +47,6 @@ export class FuzzySearchComponent implements OnInit {

ngOnInit(): void {
this.searchInputValue$ = this.searchFacade.searchFilters$.pipe(
tap((searchFilter) => (this.currentSearchFilters = searchFilter)),
map((searchFilter) => ({
title: searchFilter.any as string,
}))
Expand Down Expand Up @@ -78,8 +76,11 @@ export class FuzzySearchComponent implements OnInit {
}
}

handleInputCleared() {
if (this.currentSearchFilters.any) {
async handleInputCleared() {
const currentSearchFilters: SearchFilters = await firstValueFrom(
this.searchFacade.searchFilters$
)
if (currentSearchFilters.any) {
this.searchService.updateFilters({ any: '' })
}
}
Expand Down

0 comments on commit d94ca4a

Please sign in to comment.