@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.
@@ -1,4 +1,4 @@
1
1
  import { Config } from "../types/config";
2
- export declare const useLiveConfig: (shopifyPermanentDomain: string) => {
2
+ export declare const useLiveConfig: (shopifyPermanentDomain: string, configId?: string | undefined) => {
3
3
  config: Config | undefined;
4
4
  };
@@ -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 json = yield fetch(`https://config.search.reactify.app/?shop=${shopifyPermanentDomain}`).then((response) => response.json());
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
  };
@@ -26,6 +26,7 @@ declare const Context: React.Context<Context | undefined>;
26
26
  declare type Props = {
27
27
  index: string;
28
28
  shopifyPermanentDomain: string;
29
+ configId?: string;
29
30
  filterStackId?: string;
30
31
  collection?: Collection;
31
32
  noReactiveBase?: boolean;
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(sortOptions[0].id, true);
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";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "3.10.2",
4
+ "version": "3.11.0-beta.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",