From aac992ed30da7f3331f02504eb9eddde8ebe0b33 Mon Sep 17 00:00:00 2001 From: Rongrong Chai Date: Wed, 25 Oct 2023 16:28:40 +0000 Subject: [PATCH] enable search terms --- .../src/lib/challenge-search.component.ts | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/libs/openchallenges/challenge-search/src/lib/challenge-search.component.ts b/libs/openchallenges/challenge-search/src/lib/challenge-search.component.ts index ce5be32bb3..28c92f47ef 100644 --- a/libs/openchallenges/challenge-search/src/lib/challenge-search.component.ts +++ b/libs/openchallenges/challenge-search/src/lib/challenge-search.component.ts @@ -402,11 +402,7 @@ export class ChallengeSearchComponent takeUntil(this.destroy) ) .subscribe((searched) => { - const searchedTerms = searched === '' ? undefined : searched; - this.router.navigate([], { - queryParamsHandling: 'merge', - queryParams: { searchTerms: searchedTerms }, - }); + this.onParamChange('searchTerms', searched); }); this.query @@ -437,16 +433,6 @@ export class ChallengeSearchComponent this.destroy.complete(); } - splitParam(activeParam: string | undefined, by = ','): any[] { - return activeParam ? activeParam.split(by) : []; - } - - collapseParam(selectedParam: any, by = ','): string | undefined { - return selectedParam.length === 0 - ? undefined - : this.splitParam(selectedParam.toString()).join(by); - } - onSearchChange(): void { this.searchTerms.next(this.searchedTerms); } @@ -534,7 +520,7 @@ export class ChallengeSearchComponent }); } - onParamChange(paramName: string, selected: string[]): void { + onParamChange(paramName: string, selected: string[] | string): void { let params = new HttpParams().delete(paramName); if (selected.length > 0) { params = new HttpParams().append( @@ -549,6 +535,16 @@ export class ChallengeSearchComponent this.query.next(newQuery); } + splitParam(activeParam: string | undefined, by = ','): any[] { + return activeParam ? activeParam.split(by) : []; + } + + collapseParam(selectedParam: any, by = ','): string | undefined { + return selectedParam.length === 0 + ? undefined + : this.splitParam(selectedParam.toString()).join(by); + } + openSnackBar(message: string) { this._snackBar.open(message, undefined, { duration: 30000,