Skip to content

Commit

Permalink
restructure facet handling
Browse files Browse the repository at this point in the history
  • Loading branch information
janschulte committed Jan 31, 2025
1 parent 1bf9189 commit 86deb34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 1 addition & 9 deletions src/apps/empty/services/search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { Reactive, reactive } from "@conterra/reactivity-core";
import { DeclaredService, ServiceOptions } from "@open-pioneer/runtime";
import { CatalogService, Facet, OrderOption, SearchFilter, SearchResultEntry } from "catalog";
import { CatalogService, OrderOption, SearchFilter, SearchResultEntry } from "catalog";
import { NotificationService } from "@open-pioneer/notifier";
import { API_URL, URL_PARAM_SEARCH_TERM } from "../constants";

Expand All @@ -16,7 +16,6 @@ export interface SearchService extends DeclaredService<"SearchService"> {
results: SearchResultEntry[] | undefined;
resultCount: number;
currentFilter: SearchFilter;
facets: Facet[];
hasActiveFilter: boolean;
set pageSize(pageSize: number);
set searchTerm(searchTerm: string | undefined);
Expand All @@ -38,8 +37,6 @@ export class SearchServiceImpl implements SearchService {

#resultCount: Reactive<number> = reactive(0);

#facets: Reactive<Facet[]> = reactive([]);

#currentFilter: SearchFilter = {
pageSize: 5,
page: 1,
Expand Down Expand Up @@ -67,10 +64,6 @@ export class SearchServiceImpl implements SearchService {
return this.#currentFilter;
}

get facets(): Facet[] {
return this.#facets.value;
}

set searchTerm(term: string | undefined) {
this.#currentFilter.searchTerm = term;
this.triggerSearch();
Expand Down Expand Up @@ -152,7 +145,6 @@ export class SearchServiceImpl implements SearchService {
}
this.catalogSrvc.getFacets(API_URL).then((facets) => {
this.#currentFilter.facets = facets;
this.#facets.value = facets;
facets.forEach((facet) => facet.applyOfSearchParams(url.searchParams));
this.triggerSearch();
});
Expand Down
13 changes: 10 additions & 3 deletions src/apps/empty/views/SearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ import { useOnMountUnsafe } from "../components/helper";

export function SearchView() {
const searchSrvc = useService<SearchService>("SearchService");
const [results, loading, resultCount, facets] = useReactiveSnapshot(
() => [searchSrvc.results, searchSrvc.searching, searchSrvc.resultCount, searchSrvc.facets],
const [results, loading, resultCount, currentFilter] = useReactiveSnapshot(
() => [
searchSrvc.results,
searchSrvc.searching,
searchSrvc.resultCount,
searchSrvc.currentFilter
],
[searchSrvc]
);

Expand All @@ -46,7 +51,9 @@ export function SearchView() {
</Center>
<Grid templateColumns="400px 1fr" gap={2}>
<GridItem w="100%">
{facets?.map((f) => <FacetComp key={f.key} facet={f}></FacetComp>)}
{currentFilter.facets.map((f) => (
<FacetComp key={f.key} facet={f}></FacetComp>
))}
</GridItem>
<GridItem w="100%">
<VStack>
Expand Down

0 comments on commit 86deb34

Please sign in to comment.