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
…#142853)

(cherry picked from commit 022e59f)
  • Loading branch information
hop-dev committed Oct 10, 2022
1 parent e73f29e commit 98eb182
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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';

@@ -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 98eb182

Please sign in to comment.