Skip to content

Commit

Permalink
Bugfix: Refresh search results when clearing category filter (elastic…
Browse files Browse the repository at this point in the history
  • Loading branch information
hop-dev authored Oct 6, 2022
1 parent 4142f65 commit 022e59f
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Search as LocalSearch, PrefixIndexStrategy } from 'js-search';
import { useEffect, useRef } from 'react';
import { useRef } from 'react';

import type { IntegrationCardItem } from '../../../../common/types/models';

Expand All @@ -16,13 +16,11 @@ export const fieldsToSearch = ['name', 'title'];
export function useLocalSearch(packageList: IntegrationCardItem[]) {
const localSearchRef = useRef<LocalSearch>(new LocalSearch(searchIdField));

useEffect(() => {
const localSearch = new LocalSearch(searchIdField);
localSearch.indexStrategy = new PrefixIndexStrategy();
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
localSearch.addDocuments(packageList);
localSearchRef.current = localSearch;
}, [packageList]);
const localSearch = new LocalSearch(searchIdField);
localSearch.indexStrategy = new PrefixIndexStrategy();
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
localSearch.addDocuments(packageList);
localSearchRef.current = localSearch;

return localSearchRef;
}

0 comments on commit 022e59f

Please sign in to comment.