Skip to content

Commit

Permalink
feat: don't show titles until typing starts (#11)
Browse files Browse the repository at this point in the history
Use the idiom provided by Algolia to short circuit the query if there is no input in the form
  • Loading branch information
cdeery committed Jul 19, 2023
1 parent c5144a0 commit ed66b92
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/skills-builder/utils/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@ export const useAlgoliaSearch = () => {
config.ALGOLIA_APP_ID,
config.ALGOLIA_SEARCH_API_KEY,
);
const searchNotEmptyClient = {
...client,
search(requests) {
if (requests.every(({ params }) => !params.query)) {
return Promise.resolve({
results: requests.map(() => ({
hits: [],
nbHits: 0,
nbPages: 0,
page: 0,
processingTimeMS: 0,
hitsPerPage: 0,
exhaustiveNbHits: false,
query: '',
params: '',
})),
});
}
return client.search(requests);
},
};
const productIndex = client.initIndex(config.ALGOLIA_PRODUCT_INDEX_NAME);
const jobIndex = client.initIndex(config.ALGOLIA_JOBS_INDEX_NAME);
return [client, productIndex, jobIndex];
return [searchNotEmptyClient, productIndex, jobIndex];
},
[
config.ALGOLIA_APP_ID,
Expand Down

0 comments on commit ed66b92

Please sign in to comment.