@usereactify/search 3.10.3 → 3.11.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);
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.3",
4
+ "version": "3.11.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",