@tapcart/mobile-components 0.12.5 → 0.12.6
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.
|
@@ -2,6 +2,7 @@ import { Collection, Product, BaseSearchClient } from "app-studio-types";
|
|
|
2
2
|
interface UseRecommendationProps {
|
|
3
3
|
searchClient?: BaseSearchClient<Product>;
|
|
4
4
|
query?: string;
|
|
5
|
+
customSearchConfig?: Record<string, any>;
|
|
5
6
|
queryVariables: Record<string, any>;
|
|
6
7
|
apiURL: string;
|
|
7
8
|
}
|
|
@@ -9,9 +10,10 @@ interface UseRecommendationReturn {
|
|
|
9
10
|
products: Product[];
|
|
10
11
|
collections: Collection[];
|
|
11
12
|
searches: string[];
|
|
13
|
+
facets: any[];
|
|
12
14
|
isLoading: boolean;
|
|
13
15
|
error: any;
|
|
14
16
|
}
|
|
15
|
-
declare const useRecommendations: ({ searchClient, query, queryVariables, apiURL, }: UseRecommendationProps) => UseRecommendationReturn;
|
|
17
|
+
declare const useRecommendations: ({ searchClient, query, customSearchConfig, queryVariables, apiURL, }: UseRecommendationProps) => UseRecommendationReturn;
|
|
16
18
|
export { useRecommendations };
|
|
17
19
|
//# sourceMappingURL=use-recommendations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAOxE,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAOxE,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAGxC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAUD,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,MAAM,EAAE,GAAG,EAAE,CAAA;IACb,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,GAAG,CAAA;CACX;AAiBD,QAAA,MAAM,kBAAkB,yEASrB,sBAAsB,KAAG,uBAkG3B,CAAA;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -24,7 +24,7 @@ const getCollections = (collections) => {
|
|
|
24
24
|
const recommendationsLocalStorage = new RecommendationsLocalStorage();
|
|
25
25
|
const useRecommendations = ({
|
|
26
26
|
// Search client props
|
|
27
|
-
searchClient, query = "",
|
|
27
|
+
searchClient, query = "", customSearchConfig,
|
|
28
28
|
// API props (backwards compatibility)
|
|
29
29
|
queryVariables, apiURL, }) => {
|
|
30
30
|
// When searchClient is provided, use search client approach
|
|
@@ -40,12 +40,13 @@ queryVariables, apiURL, }) => {
|
|
|
40
40
|
const searchClientFetcher = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
41
|
if (!searchClient)
|
|
42
42
|
return null;
|
|
43
|
-
// Call searchClient.getRecommendations
|
|
43
|
+
// Call searchClient.getRecommendations with optional custom config
|
|
44
44
|
const recommendations = yield searchClient.getRecommendations({
|
|
45
45
|
query: recommendation,
|
|
46
|
+
customSearchConfig,
|
|
46
47
|
});
|
|
47
48
|
// Format as expected by the hook
|
|
48
|
-
return Object.assign({ collections: [] }, recommendations);
|
|
49
|
+
return Object.assign({ collections: [], facets: [] }, recommendations);
|
|
49
50
|
});
|
|
50
51
|
// API fetcher (backwards compatibility)
|
|
51
52
|
const apiFetcher = (body) => fetch(constructURL(apiURL), {
|
|
@@ -64,6 +65,7 @@ queryVariables, apiURL, }) => {
|
|
|
64
65
|
type: "searchClient",
|
|
65
66
|
query: recommendation,
|
|
66
67
|
language: queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language,
|
|
68
|
+
customSearchConfig,
|
|
67
69
|
}
|
|
68
70
|
: {
|
|
69
71
|
appId: queryVariables.appId,
|
|
@@ -84,12 +86,14 @@ queryVariables, apiURL, }) => {
|
|
|
84
86
|
products: data === null || data === void 0 ? void 0 : data.products,
|
|
85
87
|
collections: getCollections(data === null || data === void 0 ? void 0 : data.collections),
|
|
86
88
|
searches: data === null || data === void 0 ? void 0 : data.searches,
|
|
89
|
+
facets: (data === null || data === void 0 ? void 0 : data.facets) || [],
|
|
87
90
|
});
|
|
88
|
-
}, [data]);
|
|
91
|
+
}, [data, recommendation, queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language]);
|
|
89
92
|
return {
|
|
90
93
|
products: cachedRecommendation === null || cachedRecommendation === void 0 ? void 0 : cachedRecommendation.products,
|
|
91
94
|
collections: cachedRecommendation === null || cachedRecommendation === void 0 ? void 0 : cachedRecommendation.collections,
|
|
92
95
|
searches: cachedRecommendation === null || cachedRecommendation === void 0 ? void 0 : cachedRecommendation.searches,
|
|
96
|
+
facets: (cachedRecommendation === null || cachedRecommendation === void 0 ? void 0 : cachedRecommendation.facets) || [],
|
|
93
97
|
isLoading: !cachedRecommendation && isLoading,
|
|
94
98
|
error: error,
|
|
95
99
|
};
|