@usereactify/search 3.10.2 → 3.11.0-beta.0
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.
|
@@ -41,7 +41,7 @@ function getCachedConfig() {
|
|
|
41
41
|
}
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
const useLiveConfig = (shopifyPermanentDomain) => {
|
|
44
|
+
const useLiveConfig = (shopifyPermanentDomain, configId) => {
|
|
45
45
|
const [config, setConfig] = react_1.default.useState(getCachedConfig());
|
|
46
46
|
react_1.default.useEffect(() => {
|
|
47
47
|
const cachedConfig = getCachedConfig();
|
|
@@ -49,14 +49,19 @@ const useLiveConfig = (shopifyPermanentDomain) => {
|
|
|
49
49
|
return;
|
|
50
50
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
debug("fetching fresh config");
|
|
52
|
-
const
|
|
52
|
+
const searchParams = new URLSearchParams();
|
|
53
|
+
searchParams.set("shop", shopifyPermanentDomain);
|
|
54
|
+
if (configId) {
|
|
55
|
+
searchParams.set("id", configId);
|
|
56
|
+
}
|
|
57
|
+
const json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
|
|
53
58
|
setConfig(json.body);
|
|
54
59
|
window.sessionStorage.setItem("reactify-search:config", JSON.stringify({
|
|
55
60
|
expiresAt: new Date().getTime() + CACHE_EXPIRY,
|
|
56
61
|
config: json.body,
|
|
57
62
|
}));
|
|
58
63
|
}))();
|
|
59
|
-
}, [shopifyPermanentDomain]);
|
|
64
|
+
}, [shopifyPermanentDomain, configId]);
|
|
60
65
|
return {
|
|
61
66
|
config,
|
|
62
67
|
};
|
package/dist/provider.d.ts
CHANGED
package/dist/provider.js
CHANGED
|
@@ -27,7 +27,7 @@ const defaultCredentials = {
|
|
|
27
27
|
};
|
|
28
28
|
const Provider = (_a) => {
|
|
29
29
|
var { renderBooting } = _a, props = __rest(_a, ["renderBooting"]);
|
|
30
|
-
const { config } = (0, hooks_1.useLiveConfig)(props.shopifyPermanentDomain);
|
|
30
|
+
const { config } = (0, hooks_1.useLiveConfig)(props.shopifyPermanentDomain, props.configId);
|
|
31
31
|
if (!config) {
|
|
32
32
|
if (renderBooting)
|
|
33
33
|
return renderBooting();
|
|
@@ -83,7 +83,7 @@ const ConfiguredProvider = (props) => {
|
|
|
83
83
|
}, [searchSortFromURL]);
|
|
84
84
|
react_1.default.useEffect(() => {
|
|
85
85
|
if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.id)) {
|
|
86
|
-
setSortOption(
|
|
86
|
+
setSortOption(sortOption.id, true);
|
|
87
87
|
}
|
|
88
88
|
}, [window.location.href]);
|
|
89
89
|
const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
|
|
@@ -195,6 +195,12 @@ const useFilterStack = (config, collection, filterStackId) => react_1.default.us
|
|
|
195
195
|
if (filterStack)
|
|
196
196
|
return filterStack;
|
|
197
197
|
}
|
|
198
|
+
// automatically select filter stack by collection if provided
|
|
199
|
+
if (collection === null || collection === void 0 ? void 0 : collection.handle) {
|
|
200
|
+
const filterStack = config.filters.find((filter) => { var _a; return (_a = filter.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
|
|
201
|
+
if (filterStack)
|
|
202
|
+
return filterStack;
|
|
203
|
+
}
|
|
198
204
|
const type = !!collection ? "collection" : "search";
|
|
199
205
|
return ((_a = config.filters.find((filter) => type === filter.type)) !== null && _a !== void 0 ? _a : config.filters[0]);
|
|
200
206
|
}, [config, collection]);
|
|
@@ -120,6 +120,7 @@ export interface Filter {
|
|
|
120
120
|
pageSize: number;
|
|
121
121
|
keywords: string[];
|
|
122
122
|
defaultSort: string;
|
|
123
|
+
collections: string[];
|
|
123
124
|
type: "search" | "collection";
|
|
124
125
|
paginationType: "pagination" | "load_more" | "next_prev" | "infinite_scroll";
|
|
125
126
|
inventoryVisibility: "show_all" | "hide_products" | "hide_variants" | "hide_all";
|