tokenized text search
Some checks failed
Angular Build / build (push) Has been cancelled

This commit is contained in:
2026-03-20 20:44:59 +01:00
parent 7fe4339ce4
commit 16776e2250
6 changed files with 138 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
import {Component, DestroyRef, Input, inject} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
import {SongService} from '../../services/song.service';
import {FilterValues} from './filter-values';
import {Song} from '../../services/song';
@@ -52,7 +53,9 @@ export class FilterComponent {
this.filterFormGroup.patchValue(filterValues, {emitEvent: false});
});
this.filterFormGroup.controls.q.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(value => this.filterValueChanged('q', value));
this.filterFormGroup.controls.q.valueChanges
.pipe(debounceTime(100), distinctUntilChanged(), takeUntilDestroyed(this.destroyRef))
.subscribe(value => this.filterValueChanged('q', value));
this.filterFormGroup.controls.key.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(value => this.filterValueChanged('key', value));
this.filterFormGroup.controls.type.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(value => this.filterValueChanged('type', value));
this.filterFormGroup.controls.legalType.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(value => this.filterValueChanged('legalType', value));

View File

@@ -4,7 +4,7 @@ import {map} from 'rxjs/operators';
import {combineLatest, Observable} from 'rxjs';
import {fade} from '../../../animations';
import {ActivatedRoute, RouterLink} from '@angular/router';
import {filterSong} from '../../../services/filter.helper';
import {createSongFilter} from '../../../services/filter.helper';
import {FilterValues} from './filter/filter-values';
import {faBalanceScaleRight, faCheck, faPencilRuler, faPlus} from '@fortawesome/free-solid-svg-icons';
import {TextRenderingService} from '../services/text-rendering.service';
@@ -42,8 +42,9 @@ export class SongListComponent {
this.route.data.pipe(map(data => (data['songs'] as Song[]).slice().sort((a, b) => a.number - b.number))),
]).pipe(
map(([filter, songs]) => {
const matchesSongFilter = createSongFilter(filter.q);
return songs
.filter(song => this.filter(song, filter))
.filter(song => this.filter(song, filter, matchesSongFilter))
.map(song => ({
...song,
hasChordValidationIssues: this.textRenderingService.validateChordNotation(song.text ?? '').length > 0,
@@ -54,8 +55,8 @@ export class SongListComponent {
public trackBy = (index: number, show: SongListItem) => show.id;
private filter(song: Song, filter: FilterValues): boolean {
let baseFilter = filterSong(song, filter.q);
private filter(song: Song, filter: FilterValues, matchesSongFilter: (song: Song) => boolean): boolean {
let baseFilter = matchesSongFilter(song);
baseFilter = baseFilter && (!filter.type || filter.type === song.type);
baseFilter = baseFilter && (!filter.key || filter.key === song.key);
baseFilter = baseFilter && (!filter.legalType || filter.legalType === song.legalType);