addio-ecomm-sdk 1.3.100 → 1.3.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/constants/contexts/AutosuggestionContext/AutosuggestionContextProvider.d.ts +16 -0
- package/dist/lib/constants/contexts/AutosuggestionContext/AutosuggestionContextProvider.js +81 -0
- package/dist/lib/constants/contexts/AutosuggestionContext/AutosuggestionContextProvider.js.map +1 -0
- package/dist/lib/constants/contexts/AutosuggestionContext/index.d.ts +9 -0
- package/dist/lib/constants/contexts/AutosuggestionContext/index.js +11 -0
- package/dist/lib/constants/contexts/AutosuggestionContext/index.js.map +1 -0
- package/dist/lib/constants/hooks/useAutosuggestion.d.ts +2 -0
- package/dist/lib/constants/hooks/useAutosuggestion.js +12 -0
- package/dist/lib/constants/hooks/useAutosuggestion.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface IFacet {
|
|
3
|
+
slug: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
interface IAutosuggestionContextProvider {
|
|
7
|
+
index: string;
|
|
8
|
+
filters: IFacet[];
|
|
9
|
+
query: string;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
buildFilterStrCallback?: (_facetList: IFacet[]) => string;
|
|
12
|
+
isTestEnv?: boolean;
|
|
13
|
+
children: JSX.Element;
|
|
14
|
+
}
|
|
15
|
+
declare const AutosuggestionContextProvider: ({ index, filters, query, apiKey, buildFilterStrCallback, isTestEnv, children }: IAutosuggestionContextProvider) => JSX.Element;
|
|
16
|
+
export default AutosuggestionContextProvider;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const _1 = __importDefault(require("."));
|
|
9
|
+
const AutosuggestionContextProvider = ({ index, filters, query, apiKey, buildFilterStrCallback, isTestEnv = true, children }) => {
|
|
10
|
+
const [searchStr, setSearchStr] = (0, react_1.useState)(query);
|
|
11
|
+
const [suggestions, setSuggestions] = (0, react_1.useState)([]);
|
|
12
|
+
const SEARCH_URL = isTestEnv ? 'https://prosprsearch-dev.ciao.ca' : 'https://prosprsearch.ciao.ca';
|
|
13
|
+
const lastSearch = (0, react_1.useRef)('');
|
|
14
|
+
const searching = (0, react_1.useRef)(false);
|
|
15
|
+
const mustSearchAgain = (0, react_1.useRef)(false);
|
|
16
|
+
const buildFilterString = (_facetList) => {
|
|
17
|
+
if (!!buildFilterStrCallback)
|
|
18
|
+
return buildFilterStrCallback(_facetList);
|
|
19
|
+
const filters = _facetList.join(' OR ');
|
|
20
|
+
return filters;
|
|
21
|
+
};
|
|
22
|
+
const buildCategoryFilter = (_facetList) => {
|
|
23
|
+
return _facetList
|
|
24
|
+
.filter((f) => f.slug.startsWith('categories.'))
|
|
25
|
+
.map((f) => `${f.slug}:${f.value}`)
|
|
26
|
+
.join();
|
|
27
|
+
};
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
const text = searchStr.toLocaleLowerCase().trim();
|
|
30
|
+
if (text == lastSearch.current)
|
|
31
|
+
return;
|
|
32
|
+
lastSearch.current = text;
|
|
33
|
+
if (searching.current) {
|
|
34
|
+
mustSearchAgain.current = true;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const getSuggestions = async () => {
|
|
38
|
+
if (lastSearch.current.length < 2) {
|
|
39
|
+
setSuggestions([]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
try {
|
|
43
|
+
const req = await fetch(SEARCH_URL + `/1/indexes/${(isTestEnv ? 'test_' : 'prod_') + index}/quick`, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
47
|
+
'x-algolia-api-key': apiKey,
|
|
48
|
+
'x-algolia-application-id': apiKey
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
query: lastSearch.current,
|
|
52
|
+
hitsPerPage: 5,
|
|
53
|
+
facetFilters: buildCategoryFilter(filters),
|
|
54
|
+
filters: buildFilterString(filters),
|
|
55
|
+
page: 0,
|
|
56
|
+
facets: []
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
const hits = await req.json();
|
|
60
|
+
setSuggestions(hits.hits || []);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (mustSearchAgain.current) {
|
|
67
|
+
mustSearchAgain.current = false;
|
|
68
|
+
await getSuggestions();
|
|
69
|
+
}
|
|
70
|
+
searching.current = false;
|
|
71
|
+
};
|
|
72
|
+
searching.current = true;
|
|
73
|
+
getSuggestions();
|
|
74
|
+
}, [searchStr]);
|
|
75
|
+
const resetSuggestions = () => {
|
|
76
|
+
setSuggestions([]);
|
|
77
|
+
};
|
|
78
|
+
return ((0, jsx_runtime_1.jsx)(_1.default.Provider, Object.assign({ value: { searchStr, setSearchStr, suggestions, resetSuggestions } }, { children: children })));
|
|
79
|
+
};
|
|
80
|
+
exports.default = AutosuggestionContextProvider;
|
|
81
|
+
//# sourceMappingURL=AutosuggestionContextProvider.js.map
|
package/dist/lib/constants/contexts/AutosuggestionContext/AutosuggestionContextProvider.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutosuggestionContextProvider.js","sourceRoot":"","sources":["../../../../../src/lib/constants/contexts/AutosuggestionContext/AutosuggestionContextProvider.tsx"],"names":[],"mappings":";;;;;;AAAA,iCAAmD;AAEnD,yCAAqC;AAoBrC,MAAM,6BAA6B,GAAG,CAAC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,EAAE,CAAA;aACtB;YACD,SAAS,CAAC,OAAO,GAAG,KAAK,CAAA;QAC1B,CAAC,CAAA;QAGD,SAAS,CAAC,OAAO,GAAG,IAAI,CAAA;QACxB,cAAc,EAAE,CAAA;IACjB,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,MAAM,gBAAgB,GAAG,GAAG,EAAE;QAC7B,cAAc,CAAC,EAAE,CAAC,CAAA;IACnB,CAAC,CAAA;IAGD,OAAO,CACN,uBAAC,UAAqB,CAAC,QAAQ,kBAAC,KAAK,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAC/F,QAAQ,IACuB,CACjC,CAAA;AACF,CAAC,CAAA;AAED,kBAAe,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
export interface IAutosuggestionContext {
|
|
3
|
+
searchStr: string;
|
|
4
|
+
setSearchStr: Dispatch<SetStateAction<string>>;
|
|
5
|
+
suggestions: any[];
|
|
6
|
+
resetSuggestions?: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: import("react").Context<IAutosuggestionContext>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const getDefaultAutosuggestionContext = () => ({
|
|
5
|
+
searchStr: '',
|
|
6
|
+
setSearchStr: () => { },
|
|
7
|
+
suggestions: [],
|
|
8
|
+
resetSuggestions: () => { }
|
|
9
|
+
});
|
|
10
|
+
exports.default = (0, react_1.createContext)(getDefaultAutosuggestionContext());
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/constants/contexts/AutosuggestionContext/index.tsx"],"names":[],"mappings":";;AAAA,iCAA+D;AAS/D,MAAM,+BAA+B,GAAG,GAA2B,EAAE,CAAC,CAAC;IACtE,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,WAAW,EAAE,EAAE;IACf,gBAAgB,EAAE,GAAG,EAAE,GAAE,CAAC;CAC1B,CAAC,CAAA;AAEF,kBAAe,IAAA,qBAAa,EAAyB,+BAA+B,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const AutosuggestionContext_1 = __importDefault(require("../contexts/AutosuggestionContext"));
|
|
8
|
+
const useAutosuggestion = () => {
|
|
9
|
+
return (0, react_1.useContext)(AutosuggestionContext_1.default);
|
|
10
|
+
};
|
|
11
|
+
exports.default = useAutosuggestion;
|
|
12
|
+
//# sourceMappingURL=useAutosuggestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutosuggestion.js","sourceRoot":"","sources":["../../../../src/lib/constants/hooks/useAutosuggestion.tsx"],"names":[],"mappings":";;;;;AAAA,iCAAkC;AAClC,8FAAqE;AAErE,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC9B,OAAO,IAAA,kBAAU,EAAC,+BAAqB,CAAC,CAAA;AACzC,CAAC,CAAA;AAED,kBAAe,iBAAiB,CAAA"}
|