Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/serch by language #19

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ interface AlgoliaConfig {
algoliaOptions?: AlgoliaSearchOptions;
customOptions?: any;
instantSearchConfigs?: any;
useLanguageFilter?: boolean;
}
declare const createAlgoliaClient: (config: AlgoliaConfig) => void;

Expand Down
32 changes: 24 additions & 8 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js
// node_modules/react-is/cjs/react-is.production.min.js
var require_react_is_production_min = __commonJS({
"node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js"(exports) {
"node_modules/react-is/cjs/react-is.production.min.js"(exports) {
"use strict";
var b = "function" === typeof Symbol && Symbol.for;
var c = b ? Symbol.for("react.element") : 60103;
Expand Down Expand Up @@ -145,9 +145,9 @@ var require_react_is_production_min = __commonJS({
}
});

// node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js
// node_modules/react-is/cjs/react-is.development.js
var require_react_is_development = __commonJS({
"node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js"(exports) {
"node_modules/react-is/cjs/react-is.development.js"(exports) {
"use strict";
if (process.env.NODE_ENV !== "production") {
(function() {
Expand Down Expand Up @@ -300,9 +300,9 @@ var require_react_is_development = __commonJS({
}
});

// node_modules/prop-types/node_modules/react-is/index.js
// node_modules/react-is/index.js
var require_react_is = __commonJS({
"node_modules/prop-types/node_modules/react-is/index.js"(exports, module) {
"node_modules/react-is/index.js"(exports, module) {
"use strict";
if (process.env.NODE_ENV === "production") {
module.exports = require_react_is_production_min();
Expand Down Expand Up @@ -9126,7 +9126,15 @@ import aa2 from "search-insights";
var searchClient = {};
var searchIndex = "";
var createAlgoliaClient = (config) => {
const { apiKey, appId, index, algoliaOptions, customOptions, instantSearchConfigs } = config;
const {
apiKey,
appId,
index,
algoliaOptions,
customOptions,
instantSearchConfigs,
useLanguageFilter = false
} = config;
searchIndex = index;
aa2("init", {
appId: appId || "",
Expand All @@ -9144,6 +9152,7 @@ var createAlgoliaClient = (config) => {
...algoliaClient,
...customOptions,
instantSearchConfigs,
useLanguageFilter,
search(requests) {
if (requests.every(({ params }) => !params?.query))
return;
Expand All @@ -9167,7 +9176,14 @@ function SearchInput() {
};
return /* @__PURE__ */ jsxs31(InstantSearch, { searchClient, indexName: searchIndex, children: [
searchClient.instantSearchConfigs && /* @__PURE__ */ jsx38(Configure, { ...searchClient.instantSearchConfigs }),
/* @__PURE__ */ jsx38(Configure, { clickAnalytics: true, facetFilters: [`language:${locale}`] }),
searchClient.useLanguageFilter && /* @__PURE__ */ jsx38(
Configure,
{
clickAnalytics: true,
facetFilters: [`language:${locale}`]
}
),
!searchClient.useLanguageFilter && /* @__PURE__ */ jsx38(Configure, { clickAnalytics: true }),
/* @__PURE__ */ jsxs31(Box15, { onFocus: () => setfocusOut({ modaltoggle: true }), ref: resultsBox2, children: [
/* @__PURE__ */ jsx38(search_box_default, { changeFocus }),
focusOut.modaltoggle && /* @__PURE__ */ jsx38(results_box_default, { changeFocus })
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/components/search-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ export default function SearchInput() {

return (
<InstantSearch searchClient={searchClient} indexName={searchIndex}>
{
searchClient.instantSearchConfigs && <Configure {...searchClient.instantSearchConfigs} />
}
<Configure clickAnalytics={true} facetFilters={[`language:${locale}`]} />
{searchClient.instantSearchConfigs && (
<Configure {...searchClient.instantSearchConfigs} />
)}
{searchClient.useLanguageFilter && (
<Configure
clickAnalytics={true}
facetFilters={[`language:${locale}`]}
/>
)}
{!searchClient.useLanguageFilter && <Configure clickAnalytics={true} />}
<Box onFocus={() => setfocusOut({ modaltoggle: true })} ref={resultsBox}>
<SearchBox changeFocus={changeFocus} />
{focusOut.modaltoggle && <Results changeFocus={changeFocus} />}
Expand Down
13 changes: 12 additions & 1 deletion src/utils/config/search-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ interface AlgoliaConfig {
algoliaOptions?: AlgoliaSearchOptions
// eslint-disable-next-line @typescript-eslint/no-explicit-any
customOptions?: any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
instantSearchConfigs?: any
useLanguageFilter?: boolean
}

const createAlgoliaClient = (config: AlgoliaConfig) => {
const { apiKey, appId, index, algoliaOptions, customOptions, instantSearchConfigs } = config
const {
apiKey,
appId,
index,
algoliaOptions,
customOptions,
instantSearchConfigs,
useLanguageFilter = false,
} = config
searchIndex = index

aa('init', {
Expand All @@ -39,6 +49,7 @@ const createAlgoliaClient = (config: AlgoliaConfig) => {
...algoliaClient,
...customOptions,
instantSearchConfigs,
useLanguageFilter,
search(requests: MultipleQueriesQuery[]) {
if (requests.every(({ params }) => !params?.query)) return
return algoliaClient.search(requests)
Expand Down
Loading