Skip to content

Commit

Permalink
fix params when unselected
Browse files Browse the repository at this point in the history
  • Loading branch information
rrchai committed Oct 26, 2023
1 parent 38db3b7 commit 8744a14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,16 @@ export class ChallengeSearchComponent

onParamChange(filteredQuery: any): void {
// update params of URL
const currentParams = new HttpParams({
fromString: this._location.path().split('?')[1] ?? '',
});
const params = Object.entries(filteredQuery)
.map(([key, value]) => [key, this.collapseParam(value as FilterValue)])
.filter((pair) => pair !== null)
.reduce(
// update updated params, but ignore param if empty string
(obj, [key, value]) => (value !== '' ? obj.append(key, value) : obj),
new HttpParams()
// update with new param, or delete the param if empty string
(params, [key, value]) =>
value !== '' ? params.set(key, value) : params.delete(key),
currentParams
);
this._location.replaceState(location.pathname, params.toString());

Expand Down
10 changes: 9 additions & 1 deletion libs/openchallenges/org-search/src/lib/org-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,17 @@ export class OrgSearchComponent implements OnInit, AfterContentInit, OnDestroy {

onParamChange(filteredQuery: any): void {
// update params of URL
const currentParams = new HttpParams({
fromString: this._location.path().split('?')[1] ?? '',
});
const params = Object.entries(filteredQuery)
.map(([key, value]) => [key, this.collapseParam(value as FilterValue)])
.reduce((obj, [key, value]) => obj.append(key, value), new HttpParams());
.reduce(
// update with new param, or delete the param if empty string
(params, [key, value]) =>
value !== '' ? params.set(key, value) : params.delete(key),
currentParams
);
this._location.replaceState(location.pathname, params.toString());

// update query to trigger API call
Expand Down

0 comments on commit 8744a14

Please sign in to comment.