Skip to content

Commit

Permalink
chore: code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Feb 22, 2024
1 parent 5c5b7c8 commit 54b33d9
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export class ResourceSearchComponent implements OnInit, OnDestroy {
const searchResults = this.fuse.search(this.query);
this.setSearchResultsByType(searchResults);
this.totalResults = searchResults.length;
this.updateRoute();
this.setRouteSearchParam(this.query);
} else {
this.searchResults = { collection: [], file: [], link: [] };
this.totalResults = undefined;
this.updateRoute(true);
this.setRouteSearchParam(undefined);
}
this.cdr.markForCheck();
}
Expand All @@ -115,14 +115,9 @@ export class ResourceSearchComponent implements OnInit, OnDestroy {
this.searchResults = searchResults;
}

private updateRoute(removeParam: boolean = false) {
const queryParams = removeParam ? {} : { searchText: this.query };
/** Update route param to match search text. Passing undefined will remove the param */
private setRouteSearchParam(searchText?: string) {
const queryParams = { searchText };
this.router.navigate([], { relativeTo: this.route, queryParams });
}

goSearch() {
this.router.navigate(['/search'], {
queryParams: { searchText: this.query },
});
}
}

0 comments on commit 54b33d9

Please sign in to comment.