Skip to content

Commit

Permalink
activeFilters query param
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed Sep 5, 2023
1 parent 6dacbbc commit 5b68e1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/search/controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';

export default class SearchController extends Controller {
@tracked q?: string = '';
@tracked sort?: string = '-relevance';
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked activeFilters?: Filter[] = [];

queryParams = ['q', 'sort', 'resourceType'];
queryParams = ['q', 'sort', 'resourceType', 'activeFilters'];

@action
onSearch(queryOptions: OnSearchParams) {
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
this.activeFilters = queryOptions.activeFilters;
}
}
1 change: 1 addition & 0 deletions app/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@sort={{this.sort}}
@resourceType={{this.resourceType}}
@page={{this.page}}
@activeFilters={{this.activeFilters}}
/>
5 changes: 4 additions & 1 deletion lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface OnSearchParams {
cardSearchText?: string;
sort?: string;
resourceType?: ResourceTypeFilterValue | null;
activeFilters?: Filter[];
}

interface SearchArgs {
Expand All @@ -63,6 +64,7 @@ interface SearchArgs {
provider?: ProviderModel;
showResourceTypeFilter: boolean;
page: string;
activeFilters: Filter[];
}

const searchDebounceTime = 100;
Expand All @@ -89,6 +91,7 @@ export default class SearchPage extends Component<SearchArgs> {
this.cardSearchText = this.args.cardSearchText;
this.sort = this.args.sort;
this.resourceType = this.args.resourceType;
this.activeFilters = A<Filter>(this.args.activeFilters);
taskFor(this.search).perform();
}

Expand Down Expand Up @@ -233,7 +236,7 @@ export default class SearchPage extends Component<SearchArgs> {
this.totalResultCount = searchResult.totalResultCount === ShareMoreThanTenThousand ? '10,000+' :
searchResult.totalResultCount;
if (this.args.onSearch) {
this.args.onSearch({cardSearchText, sort, resourceType});
this.args.onSearch({cardSearchText, sort, resourceType, activeFilters});
}
} catch (e) {
this.toast.error(e);
Expand Down

0 comments on commit 5b68e1c

Please sign in to comment.