@usereactify/search 5.26.0 → 5.26.1

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.
Files changed (125) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/package.json +11 -10
  3. package/dist/src/components/ClearAll/ClearAll.js +3 -31
  4. package/dist/src/components/ClearAll/ClearAll.js.map +1 -1
  5. package/dist/src/components/Example/ExampleFilterRange.js +1 -3
  6. package/dist/src/components/Example/ExampleFilterRange.js.map +1 -1
  7. package/dist/src/components/Example/ExampleFilterSlider.js +7 -24
  8. package/dist/src/components/Example/ExampleFilterSlider.js.map +1 -1
  9. package/dist/src/components/Example/ExampleFilters.d.ts +3 -1
  10. package/dist/src/components/Example/ExampleFilters.js +4 -8
  11. package/dist/src/components/Example/ExampleFilters.js.map +1 -1
  12. package/dist/src/components/Example/ExampleFiltersSelected.js +10 -24
  13. package/dist/src/components/Example/ExampleFiltersSelected.js.map +1 -1
  14. package/dist/src/components/Example/index.d.ts +0 -3
  15. package/dist/src/components/Example/index.js +0 -3
  16. package/dist/src/components/Example/index.js.map +1 -1
  17. package/dist/src/components/Filter/Filter.d.ts +2 -2
  18. package/dist/src/components/Filter/Filter.js +18 -91
  19. package/dist/src/components/Filter/Filter.js.map +1 -1
  20. package/dist/src/components/Filter/Filters.d.ts +3 -17
  21. package/dist/src/components/Filter/Filters.js +2 -1
  22. package/dist/src/components/Filter/Filters.js.map +1 -1
  23. package/dist/src/components/Filter/FiltersSelected.d.ts +2 -7
  24. package/dist/src/components/Filter/FiltersSelected.js +2 -45
  25. package/dist/src/components/Filter/FiltersSelected.js.map +1 -1
  26. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.d.ts +7 -5
  27. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +24 -42
  28. package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
  29. package/dist/src/components/Result/Results.js +9 -24
  30. package/dist/src/components/Result/Results.js.map +1 -1
  31. package/dist/src/components/Sensor/SensorCollection.js +0 -4
  32. package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
  33. package/dist/src/components/Sensor/SensorInventoryAvailable.js +1 -6
  34. package/dist/src/components/Sensor/SensorInventoryAvailable.js.map +1 -1
  35. package/dist/src/components/Sensor/SensorPublished.js +6 -13
  36. package/dist/src/components/Sensor/SensorPublished.js.map +1 -1
  37. package/dist/src/components/Sensor/SensorSearchTerm.js +66 -92
  38. package/dist/src/components/Sensor/SensorSearchTerm.js.map +1 -1
  39. package/dist/src/components/Sensor/SensorSort.js +65 -75
  40. package/dist/src/components/Sensor/SensorSort.js.map +1 -1
  41. package/dist/src/components/Sensor/SensorSortScore.d.ts +2 -0
  42. package/dist/src/components/Sensor/SensorSortScore.js +13 -0
  43. package/dist/src/components/Sensor/SensorSortScore.js.map +1 -0
  44. package/dist/src/components/Sensor/index.d.ts +1 -0
  45. package/dist/src/components/Sensor/index.js +2 -0
  46. package/dist/src/components/Sensor/index.js.map +1 -1
  47. package/dist/src/components/index.d.ts +0 -1
  48. package/dist/src/components/index.js +0 -1
  49. package/dist/src/components/index.js.map +1 -1
  50. package/dist/src/hooks/index.d.ts +0 -3
  51. package/dist/src/hooks/index.js +0 -3
  52. package/dist/src/hooks/index.js.map +1 -1
  53. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +7 -2
  54. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +3 -10
  55. package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js.map +1 -1
  56. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +27 -0
  57. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js +71 -0
  58. package/dist/src/hooks/reactivesearch/useReactiveDataSearchProps.js.map +1 -0
  59. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.d.ts +0 -1
  60. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js +5 -3
  61. package/dist/src/hooks/reactivesearch/useReactiveFilterListProps.js.map +1 -1
  62. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.d.ts +0 -1
  63. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js +5 -3
  64. package/dist/src/hooks/reactivesearch/useReactiveFilterRangeProps.js.map +1 -1
  65. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js +1 -1
  66. package/dist/src/hooks/reactivesearch/useReactiveFilterSharedProps.js.map +1 -1
  67. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js +3 -1
  68. package/dist/src/hooks/reactivesearch/useReactiveFilterSliderProps.js.map +1 -1
  69. package/dist/src/hooks/reactivesearch/useReactiveReactProp.d.ts +1 -2
  70. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +3 -8
  71. package/dist/src/hooks/reactivesearch/useReactiveReactProp.js.map +1 -1
  72. package/dist/src/hooks/useAnalytics.js +3 -23
  73. package/dist/src/hooks/useAnalytics.js.map +1 -1
  74. package/dist/src/hooks/useConfig.js +27 -9
  75. package/dist/src/hooks/useConfig.js.map +1 -1
  76. package/dist/src/hooks/useCuration.js +1 -12
  77. package/dist/src/hooks/useCuration.js.map +1 -1
  78. package/dist/src/hooks/useFilterListProps.js +2 -15
  79. package/dist/src/hooks/useFilterListProps.js.map +1 -1
  80. package/dist/src/hooks/useFilterRangeProps.d.ts +10 -1
  81. package/dist/src/hooks/useFilterRangeProps.js +47 -36
  82. package/dist/src/hooks/useFilterRangeProps.js.map +1 -1
  83. package/dist/src/hooks/useFilterSliderProps.d.ts +8 -6
  84. package/dist/src/hooks/useFilterSliderProps.js +10 -31
  85. package/dist/src/hooks/useFilterSliderProps.js.map +1 -1
  86. package/dist/src/hooks/usePaginationLoadMore.d.ts +15 -0
  87. package/dist/src/hooks/usePaginationLoadMore.js +38 -0
  88. package/dist/src/hooks/usePaginationLoadMore.js.map +1 -0
  89. package/dist/src/hooks/useReactifySearchContext.d.ts +11 -19
  90. package/dist/src/hooks/useReactifySearchContext.js.map +1 -1
  91. package/dist/src/hooks/useSearch.js +2 -4
  92. package/dist/src/hooks/useSearch.js.map +1 -1
  93. package/dist/src/types/config.d.ts +5 -11
  94. package/dist/src/types/config.js.map +1 -1
  95. package/dist/src/types/elastic.d.ts +17 -53
  96. package/dist/src/types/elastic.js.map +1 -1
  97. package/dist/src/types/firestore.d.ts +0 -3
  98. package/dist/src/types/firestore.js.map +1 -1
  99. package/dist/src/types/reactivesearch.d.ts +1 -1
  100. package/dist/src/types/reactivesearch.js.map +1 -1
  101. package/package.json +1 -1
  102. package/dist/src/components/Example/ExampleHookUseResults.d.ts +0 -2
  103. package/dist/src/components/Example/ExampleHookUseResults.js +0 -25
  104. package/dist/src/components/Example/ExampleHookUseResults.js.map +0 -1
  105. package/dist/src/components/Example/ExampleSuggestions.d.ts +0 -4
  106. package/dist/src/components/Example/ExampleSuggestions.js +0 -16
  107. package/dist/src/components/Example/ExampleSuggestions.js.map +0 -1
  108. package/dist/src/components/Suggestions/Suggestions.d.ts +0 -12
  109. package/dist/src/components/Suggestions/Suggestions.js +0 -44
  110. package/dist/src/components/Suggestions/Suggestions.js.map +0 -1
  111. package/dist/src/components/Suggestions/index.d.ts +0 -1
  112. package/dist/src/components/Suggestions/index.js +0 -14
  113. package/dist/src/components/Suggestions/index.js.map +0 -1
  114. package/dist/src/hooks/react-slider/useReactSliderProps.d.ts +0 -4
  115. package/dist/src/hooks/react-slider/useReactSliderProps.js +0 -28
  116. package/dist/src/hooks/react-slider/useReactSliderProps.js.map +0 -1
  117. package/dist/src/hooks/useFlags.d.ts +0 -21
  118. package/dist/src/hooks/useFlags.js +0 -49
  119. package/dist/src/hooks/useFlags.js.map +0 -1
  120. package/dist/src/hooks/useIndices.d.ts +0 -5
  121. package/dist/src/hooks/useIndices.js +0 -49
  122. package/dist/src/hooks/useIndices.js.map +0 -1
  123. package/dist/src/hooks/useResults.d.ts +0 -21
  124. package/dist/src/hooks/useResults.js +0 -19
  125. package/dist/src/hooks/useResults.js.map +0 -1
@@ -15,30 +15,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.useConfig = void 0;
16
16
  const react_1 = __importDefault(require("react"));
17
17
  const utility_1 = require("../utility");
18
+ // 5 minute cache expiry
19
+ const CACHE_EXPIRY = 5 * 60 * 1000;
18
20
  const useConfig = (shopifyPermanentDomain, configId) => {
19
21
  // synchronously returns cached and non-expired config from session storage
20
22
  const cachedConfig = react_1.default.useMemo(() => {
21
- var _a, _b;
23
+ var _a;
22
24
  if (typeof window === "undefined") {
23
25
  return;
24
26
  }
25
27
  utility_1.debug.log("useConfig", "checking config cache");
28
+ // skip checking cache if url search param "nocache" is set
29
+ const skipCache = new URLSearchParams(window.location.href.split("?")[1]).get("nocache") !==
30
+ null;
31
+ if (skipCache) {
32
+ utility_1.debug.log("useConfig", "cache is disabled");
33
+ return;
34
+ }
26
35
  const sessionConfig = JSON.parse((_a = window.sessionStorage.getItem("reactify-search:config")) !== null && _a !== void 0 ? _a : "null");
27
36
  if (sessionConfig) {
28
- if (((_b = sessionConfig.config.cache) === null || _b === void 0 ? void 0 : _b.enabled) === false) {
29
- utility_1.debug.log("useConfig", `cache disabled, ignoring cached config`);
30
- return;
37
+ const sessionConfigTtl = sessionConfig.expiresAt - Date.now();
38
+ if (sessionConfigTtl > 0) {
39
+ utility_1.debug.log("useConfig", `config cache valid, expires in ${(sessionConfigTtl / 1000).toFixed()} seconds`);
40
+ return sessionConfig.config;
41
+ }
42
+ else {
43
+ utility_1.debug.log("useConfig", `config cache invalid, expired ${((sessionConfigTtl * -1) /
44
+ 1000).toFixed()} seconds ago`);
31
45
  }
32
- utility_1.debug.log("useConfig", `cache enabled, using cached config`);
33
- return sessionConfig.config;
34
- }
35
- else {
36
- utility_1.debug.log("useConfig", `cached config missing`);
37
46
  }
38
47
  return;
39
48
  }, []);
40
49
  const [config, setConfig] = react_1.default.useState(cachedConfig);
41
50
  react_1.default.useEffect(() => {
51
+ if (config) {
52
+ return;
53
+ }
42
54
  (() => __awaiter(void 0, void 0, void 0, function* () {
43
55
  utility_1.debug.log("useConfig", "loading fresh config");
44
56
  const searchParams = new URLSearchParams();
@@ -46,10 +58,16 @@ const useConfig = (shopifyPermanentDomain, configId) => {
46
58
  if (configId) {
47
59
  searchParams.set("id", configId);
48
60
  }
61
+ const skipCache = new URLSearchParams(window.location.href.split("?")[1]).get("nocache") !== null;
62
+ if (skipCache) {
63
+ searchParams.set("nocache", "true");
64
+ }
49
65
  const json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
50
66
  setConfig(json.body);
51
67
  utility_1.debug.log("useConfig", "loaded fresh config");
52
68
  window.sessionStorage.setItem("reactify-search:config", JSON.stringify({
69
+ expiresAt: new Date().getTime() + CACHE_EXPIRY,
70
+ noCache: skipCache,
53
71
  config: json.body,
54
72
  }));
55
73
  }))();
@@ -1 +1 @@
1
- {"version":3,"file":"useConfig.js","sourceRoot":"","sources":["../../../src/hooks/useConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,wCAAmC;AAE5B,MAAM,SAAS,GAAG,CACvB,sBAA8B,EAC9B,QAAiB,EAGjB,EAAE;IACF,2EAA2E;IAC3E,MAAM,YAAY,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACtC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,OAAO;SACR;QACD,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC;QAEhD,MAAM,aAAa,GAER,IAAI,CAAC,KAAK,CACnB,MAAA,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,wBAAwB,CAAC,mCAAI,MAAM,CAClE,CAAC;QAEF,IAAI,aAAa,EAAE;YACjB,IAAI,CAAA,MAAA,aAAa,CAAC,MAAM,CAAC,KAAK,0CAAE,OAAO,MAAK,KAAK,EAAE;gBACjD,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,wCAAwC,CAAC,CAAC;gBACjE,OA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QACnB,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAvEW,QAAA,SAAS,aAuEpB","sourcesContent":["import React from \"react\";\n\nimport { Config } from \"../types/config\";\nimport { debug } from \"../utility\";\n\nexport const useConfig = (\n shopifyPermanentDomain: string,\n configId?: string\n): {\n config: Config | undefined;\n} => {\n // synchronously returns cached and non-expired config from session storage\n const cachedConfig = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n debug.log(\"useConfig\", \"checking config cache\");\n\n const sessionConfig: {\n config: Config;\n } | null = JSON.parse(\n window.sessionStorage.getItem(\"reactify-search:config\") ?? \"null\"\n );\n\n if (sessionConfig) {\n if (sessionConfig.config.cache?.enabled === false) {\n debug.log(\"useConfig\", `cache disabled, ignoring cached config`);\n return;\n }\n\n debug.log(\"useConfig\", `cache enabled, using cached config`);\n\n return sessionConfig.config;\n } else {\n debug.log(\"useConfig\", `cached config missing`);\n }\n\n return;\n }, []);\n\n const [config, setConfig] = React.useState<Config | undefined>(cachedConfig);\n\n React.useEffect(() => {\n (async () => {\n debug.log(\"useConfig\", \"loading fresh config\");\n const searchParams = new URLSearchParams();\n searchParams.set(\"shop\", shopifyPermanentDomain);\n\n if (configId) {\n searchParams.set(\"id\", configId);\n }\n\n const json = await fetch(\n `https://config.search.reactify.app/?${searchParams.toString()}`\n ).then((response) => response.json());\n\n setConfig(json.body);\n\n debug.log(\"useConfig\", \"loaded fresh config\");\n\n window.sessionStorage.setItem(\n \"reactify-search:config\",\n JSON.stringify({\n config: json.body,\n })\n );\n })();\n }, [shopifyPermanentDomain, configId]);\n\n React.useEffect(() => {\n debug.log(\"useConfig\", \"config\", config);\n }, [config]);\n\n return {\n config,\n };\n};\n"]}
1
+ {"version":3,"file":"useConfig.js","sourceRoot":"","sources":["../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,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,YAAY;gBAC9C,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,IAAI,CAAC,IAAI;aAClB,CAAC,CACH,CAAC;QACJ,CAAC,CAAA,CAAC,EAAE,CAAC;IACP,CAAC,EAAE,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEvC,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AA1GW,QAAA,SAAS,aA0GpB","sourcesContent":["import React from \"react\";\n\nimport { Config } from \"../types/config\";\nimport { debug } from \"../utility\";\n\n// 5 minute cache expiry\nconst CACHE_EXPIRY = 5 * 60 * 1000;\n\nexport const useConfig = (\n shopifyPermanentDomain: string,\n configId?: string\n): {\n config: Config | undefined;\n} => {\n // synchronously returns cached and non-expired config from session storage\n const cachedConfig = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n debug.log(\"useConfig\", \"checking config cache\");\n\n // skip checking cache if url search param \"nocache\" is set\n const skipCache =\n new URLSearchParams(window.location.href.split(\"?\")[1]).get(\"nocache\") !==\n null;\n if (skipCache) {\n debug.log(\"useConfig\", \"cache is disabled\");\n\n return;\n }\n\n const sessionConfig: {\n expiresAt: number;\n config: Config;\n } | null = JSON.parse(\n window.sessionStorage.getItem(\"reactify-search:config\") ?? \"null\"\n );\n\n if (sessionConfig) {\n const sessionConfigTtl = sessionConfig.expiresAt - Date.now();\n if (sessionConfigTtl > 0) {\n debug.log(\n \"useConfig\",\n `config cache valid, expires in ${(\n sessionConfigTtl / 1000\n ).toFixed()} seconds`\n );\n\n return sessionConfig.config;\n } else {\n debug.log(\n \"useConfig\",\n `config cache invalid, expired ${(\n (sessionConfigTtl * -1) /\n 1000\n ).toFixed()} seconds ago`\n );\n }\n }\n\n return;\n }, []);\n\n const [config, setConfig] = React.useState<Config | undefined>(cachedConfig);\n\n React.useEffect(() => {\n if (config) {\n return;\n }\n\n (async () => {\n debug.log(\"useConfig\", \"loading fresh config\");\n const searchParams = new URLSearchParams();\n searchParams.set(\"shop\", shopifyPermanentDomain);\n\n if (configId) {\n searchParams.set(\"id\", configId);\n }\n\n const skipCache =\n new URLSearchParams(window.location.href.split(\"?\")[1]).get(\n \"nocache\"\n ) !== null;\n\n if (skipCache) {\n searchParams.set(\"nocache\", \"true\");\n }\n\n const json = await fetch(\n `https://config.search.reactify.app/?${searchParams.toString()}`\n ).then((response) => response.json());\n\n setConfig(json.body);\n\n debug.log(\"useConfig\", \"loaded fresh config\");\n\n window.sessionStorage.setItem(\n \"reactify-search:config\",\n JSON.stringify({\n expiresAt: new Date().getTime() + CACHE_EXPIRY,\n noCache: skipCache,\n config: json.body,\n })\n );\n })();\n }, [shopifyPermanentDomain, configId]);\n\n React.useEffect(() => {\n debug.log(\"useConfig\", \"config\", config);\n }, [config]);\n\n return {\n config,\n };\n};\n"]}
@@ -15,18 +15,7 @@ const useCuration = () => {
15
15
  const normalisedHandleOrSearchTerm = handleOrSearchTerm
16
16
  .toLowerCase()
17
17
  .trim();
18
- const globalCuration = config.curations.find((curation) => {
19
- if (options.mode === "search") {
20
- return curation.id === "global_search";
21
- }
22
- if (options.mode === "instant-search") {
23
- return curation.id === "global_search";
24
- }
25
- if (options.mode === "collection") {
26
- return curation.id === "global_collection";
27
- }
28
- return false;
29
- });
18
+ const globalCuration = config.curations.find((curation) => curation.id === "global");
30
19
  const curation = config.curations.find((curation) => {
31
20
  var _a, _b;
32
21
  const normalisedSearchTerm = (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
@@ -1 +1 @@
1
- {"version":3,"file":"useCuration.js","sourceRoot":"","sources":["../../../src/hooks/useCuration.ts"],"names":[],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MAAM;QACN,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;QACpE,UAAU;KACX,CAAC,CAAC;IAEH,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO;QACL,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC,CAAC;AArGW,QAAA,WAAW,eAqGtB","sourcesContent":["import React from \"react\";\n\nimport { ConfigCuration } from \"../types\";\nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): {\n curation?: ConfigCuration;\n} => {\n const { options, config } = useReactifySearchContext();\n const { searchTerm } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchTerm;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find((curation) => {\n if (options.mode === \"search\") {\n return curation.id === \"global_search\";\n }\n if (options.mode === \"instant-search\") {\n return curation.id === \"global_search\";\n }\n if (options.mode === \"collection\") {\n return curation.id === \"global_collection\";\n }\n return false;\n });\n\n const curation = config.curations.find((curation) => {\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\n\n if (\"instant-search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"collection\" === options.mode) {\n return (\n \"collection\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedCollectionHandle\n );\n }\n\n return false;\n });\n\n const addGlobalBoosting = (curation: ConfigCuration) => {\n if (!globalCuration) {\n return curation;\n }\n\n const curationIsCollection = curation.type === \"collection\";\n if (!curationIsCollection) {\n return curation;\n }\n\n const curationHasRules =\n !!curation.boosting.groupings.length ||\n !!curation.boosting.sortings.length;\n\n if (curationHasRules) {\n return curation;\n }\n\n const curationWithGlobalBoosting = {\n ...curation,\n boosting: globalCuration.boosting,\n } as ConfigCuration;\n\n return curationWithGlobalBoosting;\n };\n\n return curation\n ? addGlobalBoosting(curation)\n : globalCuration\n ? globalCuration\n : undefined;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n searchTerm,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return {\n curation: curation,\n };\n};\n"]}
1
+ {"version":3,"file":"useCuration.js","sourceRoot":"","sources":["../../../src/hooks/useCuration.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAA+D;AAC/D,wCAAmC;AAE5B,MAAM,WAAW,GAAG,GAEzB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,QAAQ,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAClC,MAAM,kBAAkB,GACtB,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC;QAExE,MAAM,4BAA4B,GAAG,kBAAkB;aACpD,WAAW,EAAE;aACb,IAAI,EAAE,CAAC;QAEV,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAC1C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,QAAQ,CACvC,CAAC;QAEF,MAAM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9B,QAAQ,KACX,QAAQ,EAAE,cAAc,CAAC,QAAQ,GAChB,CAAC;YAEpB,OAAO,0BAA0B,CAAC;QACpC,CAAC,CAAC;QAEF,OAAO,QAAQ;YACb,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC;YAC7B,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC,EAAE;QACD,MAAM;QACN,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;QACpE,UAAU;KACX,CAAC,CAAC;IAEH,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO;QACL,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC,CAAC;AA5FW,QAAA,WAAW,eA4FtB","sourcesContent":["import React from \"react\";\n\nimport { ConfigCuration } from \"../types\";\nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): {\n curation?: ConfigCuration;\n} => {\n const { options, config } = useReactifySearchContext();\n const { searchTerm } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchTerm;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find(\n (curation) => curation.id === \"global\"\n );\n\n const curation = config.curations.find((curation) => {\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\n\n if (\"instant-search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"collection\" === options.mode) {\n return (\n \"collection\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedCollectionHandle\n );\n }\n\n return false;\n });\n\n const addGlobalBoosting = (curation: ConfigCuration) => {\n if (!globalCuration) {\n return curation;\n }\n\n const curationIsCollection = curation.type === \"collection\";\n if (!curationIsCollection) {\n return curation;\n }\n\n const curationHasRules =\n !!curation.boosting.groupings.length ||\n !!curation.boosting.sortings.length;\n\n if (curationHasRules) {\n return curation;\n }\n\n const curationWithGlobalBoosting = {\n ...curation,\n boosting: globalCuration.boosting,\n } as ConfigCuration;\n\n return curationWithGlobalBoosting;\n };\n\n return curation\n ? addGlobalBoosting(curation)\n : globalCuration\n ? globalCuration\n : undefined;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n searchTerm,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return {\n curation: curation,\n };\n};\n"]}
@@ -9,11 +9,6 @@ const hooks_1 = require("../hooks");
9
9
  const utility_1 = require("../utility");
10
10
  const DEFAULT_NUMERIC_SORT = ["0000", "000", "00", "0"];
11
11
  const DEFAULT_ALPHABETICAL_SORT = [
12
- "SINGLE",
13
- "DOUBLE",
14
- "QUEEN",
15
- "KING",
16
- "SUPER KING",
17
12
  "XXXS",
18
13
  "XXS",
19
14
  "XS",
@@ -40,7 +35,6 @@ const DEFAULT_ALPHABETICAL_SORT = [
40
35
  ];
41
36
  // converts reactivesearch props returned in filters to a cleaned up/filtered version
42
37
  const useFilterListProps = (filter, reactivesearchFilterProps) => {
43
- var _a;
44
38
  const { track } = (0, hooks_1.useAnalytics)();
45
39
  const handleChange = react_1.default.useCallback((key) => {
46
40
  utility_1.debug.breadcrumb({
@@ -62,7 +56,6 @@ const useFilterListProps = (filter, reactivesearchFilterProps) => {
62
56
  },
63
57
  });
64
58
  }, [filter]);
65
- const customSortOrder = (_a = filter.customSortOrder) === null || _a === void 0 ? void 0 : _a.split(",").map((item) => item.trim().toUpperCase());
66
59
  const filterListProps = react_1.default.useMemo(() => {
67
60
  // remove excluded options, sort alphabeticaly, map checked boolean
68
61
  const options = reactivesearchFilterProps.data
@@ -77,14 +70,8 @@ const useFilterListProps = (filter, reactivesearchFilterProps) => {
77
70
  .sort((a, b) => DEFAULT_NUMERIC_SORT.indexOf(a.key) -
78
71
  DEFAULT_NUMERIC_SORT.indexOf(b.key))
79
72
  .sort((a, b) => new Intl.Collator("en", { numeric: true, sensitivity: "base" }).compare(a.key, b.key))
80
- .sort((a, b) => {
81
- if (!customSortOrder || customSortOrder.length === 0) {
82
- return (DEFAULT_ALPHABETICAL_SORT.indexOf(a.key.toUpperCase()) -
83
- DEFAULT_ALPHABETICAL_SORT.indexOf(b.key.toUpperCase()));
84
- }
85
- return ((customSortOrder === null || customSortOrder === void 0 ? void 0 : customSortOrder.indexOf(a.key.toUpperCase())) -
86
- (customSortOrder === null || customSortOrder === void 0 ? void 0 : customSortOrder.indexOf(b.key.toUpperCase())));
87
- })
73
+ .sort((a, b) => DEFAULT_ALPHABETICAL_SORT.indexOf(a.key) -
74
+ DEFAULT_ALPHABETICAL_SORT.indexOf(b.key))
88
75
  .map((option) => (Object.assign(Object.assign({}, option), { label: filter.settingsUppercase ? option.key.toUpperCase() : option.key, checked: (typeof reactivesearchFilterProps.value === "object" &&
89
76
  reactivesearchFilterProps.value[option.key]) ||
90
77
  reactivesearchFilterProps.value === option.key })));
@@ -1 +1 @@
1
- {"version":3,"file":"useFilterListProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterListProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,oCAAwC;AACxC,wCAAmC;AAEnC,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AACxD,MAAM,yBAAyB,GAAG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sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../types/config\";\nimport { ReactivesearchFilterListProps } from \"../types/reactivesearch\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nconst DEFAULT_NUMERIC_SORT = [\"0000\", \"000\", \"00\", \"0\"];\nconst DEFAULT_ALPHABETICAL_SORT = [\n \"SINGLE\",\n \"DOUBLE\",\n \"QUEEN\",\n \"KING\",\n \"SUPER KING\",\n \"XXXS\",\n \"XXS\",\n \"XS\",\n \"XS/S\",\n \"S\",\n \"SM\",\n \"S/M\",\n \"M\",\n \"ML\",\n \"M/L\",\n \"L\",\n \"LXL\",\n \"L/XL\",\n \"XL\",\n \"2L\",\n \"XXL\",\n \"3L\",\n \"XXXL\",\n \"4L\",\n \"5L\",\n \"6L\",\n \"OS\",\n \"ONESIZE\",\n];\n\n// converts reactivesearch props returned in filters to a cleaned up/filtered version\nexport const useFilterListProps = (\n filter: ConfigFilterOption,\n reactivesearchFilterProps: ReactivesearchFilterListProps\n): ReactivesearchFilterListProps & {\n filter: ConfigFilterOption;\n options: Array<{\n doc_count: number;\n key: string;\n label: string;\n checked: boolean;\n }>;\n hasSelected: boolean;\n totalSelected: number;\n} => {\n const { track } = useAnalytics();\n\n const handleChange = React.useCallback(\n (key: string) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: key,\n },\n });\n\n debug.log(\"useFilterListProps\", \"handleChange[key]\", key);\n\n reactivesearchFilterProps.handleChange(key);\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: key,\n },\n });\n },\n [filter]\n );\n\n const customSortOrder = filter.customSortOrder\n ?.split(\",\")\n .map((item) => item.trim().toUpperCase());\n\n const filterListProps = React.useMemo(() => {\n // remove excluded options, sort alphabeticaly, map checked boolean\n const options = reactivesearchFilterProps.data\n .filter(({ key }) => {\n if (filter.valuesExclude?.includes(key)) return false;\n if (!!filter.valuesManual?.length && !filter.valuesManual.includes(key))\n return false;\n return true;\n })\n .sort(\n (a, b) =>\n DEFAULT_NUMERIC_SORT.indexOf(a.key) -\n DEFAULT_NUMERIC_SORT.indexOf(b.key)\n )\n .sort((a, b) =>\n new Intl.Collator(\"en\", { numeric: true, sensitivity: \"base\" }).compare(\n a.key,\n b.key\n )\n )\n .sort((a, b) => {\n if (!customSortOrder || customSortOrder.length === 0) {\n return (\n DEFAULT_ALPHABETICAL_SORT.indexOf(a.key.toUpperCase()) -\n DEFAULT_ALPHABETICAL_SORT.indexOf(b.key.toUpperCase())\n );\n }\n\n return (\n customSortOrder?.indexOf(a.key.toUpperCase()) -\n customSortOrder?.indexOf(b.key.toUpperCase())\n );\n })\n .map((option) => ({\n ...option,\n label: filter.settingsUppercase ? option.key.toUpperCase() : option.key,\n checked:\n (typeof reactivesearchFilterProps.value === \"object\" &&\n reactivesearchFilterProps.value[option.key]) ||\n reactivesearchFilterProps.value === option.key,\n }));\n\n // work out if at least one option selected\n const hasSelected =\n (typeof reactivesearchFilterProps.value === \"object\" &&\n 0 < Object.keys(reactivesearchFilterProps.value).length) ||\n (typeof reactivesearchFilterProps.value !== \"object\" &&\n !!reactivesearchFilterProps.value);\n\n const totalSelected = options.filter((option) => option.checked).length;\n\n return {\n ...reactivesearchFilterProps,\n handleChange,\n filter,\n options,\n hasSelected,\n totalSelected,\n };\n }, [filter, handleChange, reactivesearchFilterProps]);\n\n return filterListProps;\n};\n"]}
1
+ {"version":3,"file":"useFilterListProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterListProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,oCAAwC;AACxC,wCAAmC;AAEnC,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AACxD,MAAM,yBAAyB,GAAG;IAChC,MAAM;IACN,KAAK;IACL,IAAI;IACJ,MAAM;IACN,GAAG;IACH,IAAI;IACJ,KAAK;IAC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AC,GAAG,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;YAC1D,CAAC,OAAO,yBAAyB,CAAC,KAAK,KAAK,QAAQ;gBAClD,CAAC,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;QAEvC,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;QAExE,uCACK,yBAAyB,KAC5B,YAAY;YACZ,MAAM;YACN,OAAO;YACP,WAAW;YACX,aAAa,IACb;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,yBAAyB,CAAC,CAAC,CAAC;IAEtD,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAhGW,QAAA,kBAAkB,sBAgG7B","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../types/config\";\nimport { ReactivesearchFilterListProps } from \"../types/reactivesearch\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nconst DEFAULT_NUMERIC_SORT = [\"0000\", \"000\", \"00\", \"0\"];\nconst DEFAULT_ALPHABETICAL_SORT = [\n \"XXXS\",\n \"XXS\",\n \"XS\",\n \"XS/S\",\n \"S\",\n \"SM\",\n \"S/M\",\n \"M\",\n \"ML\",\n \"M/L\",\n \"L\",\n \"LXL\",\n \"L/XL\",\n \"XL\",\n \"2L\",\n \"XXL\",\n \"3L\",\n \"XXXL\",\n \"4L\",\n \"5L\",\n \"6L\",\n \"OS\",\n \"ONESIZE\",\n];\n\n// converts reactivesearch props returned in filters to a cleaned up/filtered version\nexport const useFilterListProps = (\n filter: ConfigFilterOption,\n reactivesearchFilterProps: ReactivesearchFilterListProps\n): ReactivesearchFilterListProps & {\n filter: ConfigFilterOption;\n options: Array<{\n doc_count: number;\n key: string;\n label: string;\n checked: boolean;\n }>;\n hasSelected: boolean;\n totalSelected: number;\n} => {\n const { track } = useAnalytics();\n\n const handleChange = React.useCallback(\n (key: string) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: key,\n },\n });\n\n debug.log(\"useFilterListProps\", \"handleChange[key]\", key);\n\n reactivesearchFilterProps.handleChange(key);\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: key,\n },\n });\n },\n [filter]\n );\n\n const filterListProps = React.useMemo(() => {\n // remove excluded options, sort alphabeticaly, map checked boolean\n const options = reactivesearchFilterProps.data\n .filter(({ key }) => {\n if (filter.valuesExclude?.includes(key)) return false;\n if (!!filter.valuesManual?.length && !filter.valuesManual.includes(key))\n return false;\n return true;\n })\n .sort(\n (a, b) =>\n DEFAULT_NUMERIC_SORT.indexOf(a.key) -\n DEFAULT_NUMERIC_SORT.indexOf(b.key)\n )\n .sort((a, b) =>\n new Intl.Collator(\"en\", { numeric: true, sensitivity: \"base\" }).compare(\n a.key,\n b.key\n )\n )\n .sort(\n (a, b) =>\n DEFAULT_ALPHABETICAL_SORT.indexOf(a.key) -\n DEFAULT_ALPHABETICAL_SORT.indexOf(b.key)\n )\n .map((option) => ({\n ...option,\n label: filter.settingsUppercase ? option.key.toUpperCase() : option.key,\n checked:\n (typeof reactivesearchFilterProps.value === \"object\" &&\n reactivesearchFilterProps.value[option.key]) ||\n reactivesearchFilterProps.value === option.key,\n }));\n\n // work out if at least one option selected\n const hasSelected =\n (typeof reactivesearchFilterProps.value === \"object\" &&\n 0 < Object.keys(reactivesearchFilterProps.value).length) ||\n (typeof reactivesearchFilterProps.value !== \"object\" &&\n !!reactivesearchFilterProps.value);\n\n const totalSelected = options.filter((option) => option.checked).length;\n\n return {\n ...reactivesearchFilterProps,\n handleChange,\n filter,\n options,\n hasSelected,\n totalSelected,\n };\n }, [filter, handleChange, reactivesearchFilterProps]);\n\n return filterListProps;\n};\n"]}
@@ -1,5 +1,15 @@
1
1
  import { ConfigFilterOption } from "../types/config";
2
2
  export declare const useFilterRangeProps: (filter: ConfigFilterOption) => {
3
+ filter: ConfigFilterOption;
4
+ options: Array<{
5
+ key: string;
6
+ label: string;
7
+ checked: boolean;
8
+ }>;
9
+ value: string;
10
+ handleChange: (key: string) => void;
11
+ };
12
+ export declare const useFilterRangeMultiProps: (filter: ConfigFilterOption) => {
3
13
  filter: ConfigFilterOption;
4
14
  options: Array<{
5
15
  key: string;
@@ -8,5 +18,4 @@ export declare const useFilterRangeProps: (filter: ConfigFilterOption) => {
8
18
  }>;
9
19
  values: string[];
10
20
  handleChange: (key: string) => void;
11
- handleClear: () => void;
12
21
  };
@@ -3,13 +3,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useFilterRangeProps = void 0;
6
+ exports.useFilterRangeMultiProps = exports.useFilterRangeProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const hooks_1 = require("../hooks");
9
9
  const utility_1 = require("../utility");
10
10
  const useFilterRangeProps = (filter) => {
11
11
  const { track } = (0, hooks_1.useAnalytics)();
12
- const [filterValues, setFilterValues] = react_1.default.useState([]);
12
+ const [filterValue, setFilterValue] = react_1.default.useState("");
13
+ const handleChange = react_1.default.useCallback((key) => {
14
+ utility_1.debug.breadcrumb({
15
+ category: "filter",
16
+ message: "filter option changed",
17
+ data: {
18
+ filter: filter.name,
19
+ field: filter.field,
20
+ value: key,
21
+ },
22
+ });
23
+ utility_1.debug.log("useFilterRangeProps", "handleChange[key]", key);
24
+ setFilterValue(key);
25
+ track({
26
+ eventName: "filterChange",
27
+ payload: {
28
+ name: filter.name,
29
+ value: key,
30
+ },
31
+ });
32
+ }, [filter]);
33
+ const filterRangeProps = react_1.default.useMemo(() => {
34
+ var _a, _b;
35
+ const options = (_b = (_a = filter.displayRangeOptions) === null || _a === void 0 ? void 0 : _a.map((option) => {
36
+ const [key] = option.split(":");
37
+ return {
38
+ key: key,
39
+ label: filter.settingsUppercase ? key.toUpperCase() : key,
40
+ checked: filterValue === key,
41
+ };
42
+ })) !== null && _b !== void 0 ? _b : [];
43
+ return {
44
+ handleChange,
45
+ filter,
46
+ value: filterValue,
47
+ options,
48
+ };
49
+ }, [filter, filterValue, handleChange]);
50
+ return filterRangeProps;
51
+ };
52
+ exports.useFilterRangeProps = useFilterRangeProps;
53
+ const useFilterRangeMultiProps = (filter) => {
54
+ const { track } = (0, hooks_1.useAnalytics)();
55
+ const [filterValues, setFilterValues] = react_1.default.useState([""]);
13
56
  const handleChange = react_1.default.useCallback((key) => {
14
57
  utility_1.debug.breadcrumb({
15
58
  category: "filter",
@@ -21,15 +64,7 @@ const useFilterRangeProps = (filter) => {
21
64
  },
22
65
  });
23
66
  utility_1.debug.log("useFilterRangeMultiProps", "handleChange[key]", key);
24
- if (filter.displayType === "multi") {
25
- const selected = filterValues.find((item) => item === key)
26
- ? filterValues.filter((value) => value !== key)
27
- : [...filterValues, key];
28
- setFilterValues(selected);
29
- }
30
- if (filter.displayType === "single") {
31
- setFilterValues([key]);
32
- }
67
+ setFilterValues([...filterValues, key]);
33
68
  track({
34
69
  eventName: "filterChange",
35
70
  payload: {
@@ -38,29 +73,6 @@ const useFilterRangeProps = (filter) => {
38
73
  },
39
74
  });
40
75
  }, [filter, filterValues]);
41
- const handleClear = react_1.default.useCallback(() => {
42
- setFilterValues([]);
43
- }, []);
44
- react_1.default.useEffect(() => {
45
- var _a;
46
- try {
47
- if (filter.displayView === "range") {
48
- const url = new URL(window.location.href);
49
- const value = JSON.parse((_a = url.searchParams.get(filter.handle)) !== null && _a !== void 0 ? _a : "[]");
50
- setFilterValues(value);
51
- }
52
- }
53
- catch (error) {
54
- console.error(error);
55
- }
56
- }, []);
57
- react_1.default.useEffect(() => {
58
- const handler = (event) => {
59
- setFilterValues(event.detail.value);
60
- };
61
- window.addEventListener(`@usereactify/search:filter:${filter.handle}:update`, handler);
62
- return () => window.removeEventListener(`@usereactify/search:filter:${filter.handle}:update`, handler);
63
- }, []);
64
76
  const filterRangeProps = react_1.default.useMemo(() => {
65
77
  var _a, _b;
66
78
  const options = (_b = (_a = filter.displayRangeOptions) === null || _a === void 0 ? void 0 : _a.map((option) => {
@@ -73,7 +85,6 @@ const useFilterRangeProps = (filter) => {
73
85
  })) !== null && _b !== void 0 ? _b : [];
74
86
  return {
75
87
  handleChange,
76
- handleClear,
77
88
  filter,
78
89
  values: filterValues,
79
90
  options,
@@ -81,5 +92,5 @@ const useFilterRangeProps = (filter) => {
81
92
  }, [filter, filterValues, handleChange]);
82
93
  return filterRangeProps;
83
94
  };
84
- exports.useFilterRangeProps = useFilterRangeProps;
95
+ exports.useFilterRangeMultiProps = useFilterRangeMultiProps;
85
96
  //# sourceMappingURL=useFilterRangeProps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFilterRangeProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterRangeProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAwC;AACxC,wCAAmC;AAE5B,MAAM,mBAAmB,GAAG,CACjC,MAA0B,EAW1B,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IACjC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAW,EAAE,CAAC,CAAC;IAErE,MAAM,YAAY,GAAG,eAAK,CAAC,WAAW,CACpC,CAAC,GAAW,EAAE,EAAE;QACd,eAAK,CAAC,UAAU,CAAC;YACf,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,uBAAuB;YAChC,IAAI,EAAE;gBACJ,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAC;QAEH,eAAK,CAAC,GAAG,CAAC,0BAA0B,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;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types/config\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilterRangeProps = (\n filter: ConfigFilterOption\n): {\n filter: ConfigFilterOption;\n options: Array<{\n key: string;\n label: string;\n checked: boolean;\n }>;\n values: string[];\n handleChange: (key: string) => void;\n handleClear: () => void;\n} => {\n const { track } = useAnalytics();\n const [filterValues, setFilterValues] = React.useState<string[]>([]);\n\n const handleChange = React.useCallback(\n (key: string) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: key,\n },\n });\n\n debug.log(\"useFilterRangeMultiProps\", \"handleChange[key]\", key);\n\n if (filter.displayType === \"multi\") {\n const selected = filterValues.find((item: string) => item === key)\n ? filterValues.filter((value) => value !== key)\n : [...filterValues, key];\n\n setFilterValues(selected);\n }\n if (filter.displayType === \"single\") {\n setFilterValues([key]);\n }\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: key,\n },\n });\n },\n [filter, filterValues]\n );\n\n const handleClear = React.useCallback(() => {\n setFilterValues([]);\n }, []);\n\n React.useEffect(() => {\n try {\n if (filter.displayView === \"range\") {\n const url = new URL(window.location.href);\n const value = JSON.parse(url.searchParams.get(filter.handle) ?? \"[]\");\n setFilterValues(value);\n }\n } catch (error) {\n console.error(error);\n }\n }, []);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<{ handle: string; value: Array<string> }>\n ) => {\n setFilterValues(event.detail.value);\n };\n window.addEventListener(\n `@usereactify/search:filter:${filter.handle}:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:filter:${filter.handle}:update`,\n handler as EventListener\n );\n }, []);\n\n const filterRangeProps = React.useMemo(() => {\n const options =\n filter.displayRangeOptions?.map((option) => {\n const [key] = option.split(\":\");\n return {\n key: key,\n label: filter.settingsUppercase ? key.toUpperCase() : key,\n checked: filterValues.includes(key),\n };\n }) ?? [];\n\n return {\n handleChange,\n handleClear,\n filter,\n values: filterValues,\n options,\n };\n }, [filter, filterValues, handleChange]);\n\n return filterRangeProps;\n};\n"]}
1
+ {"version":3,"file":"useFilterRangeProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterRangeProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAwC;AACxC,wCAAmC;AAE5B,MAAM,mBAAmB,GAAG,CACjC,MAA0B,EAU1B,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IACjC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAS,EAAE,CAAC,CAAC;IAEjE,MAAM,YAAY,GAAG,eAAK,CAAC,WAAW,CACpC,CAAC,GAAW,EAAE,EAAE;QACd,eAAK,CAAC,UAAU,CAAC;YACf,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,uBAAuB;YAChC,IAAI,EAAE;gBACJ,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAC;QAEH,eAAK,CAAC,GAAG,CAAC,qBAAqB,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;QAE3D,cAAc,CAAC,GAAG,CAAC,CAAC;QAEpB,KAAK,CAAC;YACJ,SAAS,EAAE,cAAc;YACzB,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,gBAAgB,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC1C,MAAM,OAAO,GACX,MAAA,MAAA,MAAM,CAAC,mBAAmB,0CAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACzC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK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I;gBACjB,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,EAAE,YAAY,CAAC,CACvB,CAAC;IAEF,MAAM,gBAAgB,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC1C,MAAM,OAAO,GACX,MAAA,MAAA,MAAM,CAAC,mBAAmB,0CAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACzC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO;gBACL,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG;gBACzD,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC,mCAAI,EAAE,CAAC;QAEX,OAAO;YACL,YAAY;YACZ,MAAM;YACN,MAAM,EAAE,YAAY;YACpB,OAAO;SACR,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;IAEzC,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AA9DW,QAAA,wBAAwB,4BA8DnC","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../types/config\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilterRangeProps = (\n filter: ConfigFilterOption\n): {\n filter: ConfigFilterOption;\n options: Array<{\n key: string;\n label: string;\n checked: boolean;\n }>;\n value: string;\n handleChange: (key: string) => void;\n} => {\n const { track } = useAnalytics();\n const [filterValue, setFilterValue] = React.useState<string>(\"\");\n\n const handleChange = React.useCallback(\n (key: string) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: key,\n },\n });\n\n debug.log(\"useFilterRangeProps\", \"handleChange[key]\", key);\n\n setFilterValue(key);\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: key,\n },\n });\n },\n [filter]\n );\n\n const filterRangeProps = React.useMemo(() => {\n const options =\n filter.displayRangeOptions?.map((option) => {\n const [key] = option.split(\":\");\n return {\n key: key,\n label: filter.settingsUppercase ? key.toUpperCase() : key,\n checked: filterValue === key,\n };\n }) ?? [];\n\n return {\n handleChange,\n filter,\n value: filterValue,\n options,\n };\n }, [filter, filterValue, handleChange]);\n\n return filterRangeProps;\n};\n\nexport const useFilterRangeMultiProps = (\n filter: ConfigFilterOption\n): {\n filter: ConfigFilterOption;\n options: Array<{\n key: string;\n label: string;\n checked: boolean;\n }>;\n values: string[];\n handleChange: (key: string) => void;\n} => {\n const { track } = useAnalytics();\n const [filterValues, setFilterValues] = React.useState<string[]>([\"\"]);\n\n const handleChange = React.useCallback(\n (key: string) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: key,\n },\n });\n\n debug.log(\"useFilterRangeMultiProps\", \"handleChange[key]\", key);\n\n setFilterValues([...filterValues, key]);\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: key,\n },\n });\n },\n [filter, filterValues]\n );\n\n const filterRangeProps = React.useMemo(() => {\n const options =\n filter.displayRangeOptions?.map((option) => {\n const [key] = option.split(\":\");\n return {\n key: key,\n label: filter.settingsUppercase ? key.toUpperCase() : key,\n checked: filterValues.includes(key),\n };\n }) ?? [];\n\n return {\n handleChange,\n filter,\n values: filterValues,\n options,\n };\n }, [filter, filterValues, handleChange]);\n\n return filterRangeProps;\n};\n"]}
@@ -1,10 +1,12 @@
1
1
  import { ConfigFilterOption } from "../types/config";
2
- import { useReactSliderProps } from "./react-slider/useReactSliderProps";
3
2
  export declare const useFilterSliderProps: (filter: ConfigFilterOption) => {
4
3
  filter: ConfigFilterOption;
5
- value: [number, number];
6
- range: [number, number];
7
- handleChange: (value: [number | string, number | string]) => void;
8
- handleRange: (value: [number, number]) => void;
9
- reactSliderProps: ReturnType<typeof useReactSliderProps>;
4
+ value: {
5
+ start: number;
6
+ end: number;
7
+ };
8
+ handleChange: (value: {
9
+ start: number | string;
10
+ end: number | string;
11
+ }) => void;
10
12
  };
@@ -7,15 +7,12 @@ exports.useFilterSliderProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const hooks_1 = require("../hooks");
9
9
  const utility_1 = require("../utility");
10
- const useReactSliderProps_1 = require("./react-slider/useReactSliderProps");
11
10
  const useFilterSliderProps = (filter) => {
12
- var _a;
13
11
  const { track } = (0, hooks_1.useAnalytics)();
14
- const urlSearchParam = new URLSearchParams(window.location.search);
15
- const [filterValue, setFilterValue] = react_1.default.useState(JSON.parse((_a = urlSearchParam.get(filter.handle)) !== null && _a !== void 0 ? _a : "[0,0]"));
16
- const [filterRange, setFilterRange] = react_1.default.useState([
17
- 0, 0,
18
- ]);
12
+ const [filterValue, setFilterValue] = react_1.default.useState({
13
+ start: 0,
14
+ end: 0,
15
+ });
19
16
  const handleChange = react_1.default.useCallback((value) => {
20
17
  utility_1.debug.breadcrumb({
21
18
  category: "filter",
@@ -27,43 +24,25 @@ const useFilterSliderProps = (filter) => {
27
24
  },
28
25
  });
29
26
  utility_1.debug.log("useFilterSliderProps", "handleChange[value]", value);
30
- setFilterValue([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);
27
+ setFilterValue({
28
+ start: parseInt(`${value.start}`),
29
+ end: parseInt(`${value.end}`),
30
+ });
31
31
  track({
32
32
  eventName: "filterChange",
33
33
  payload: {
34
34
  name: filter.name,
35
- value: `${value[0]}:${value[1]}`,
35
+ value: `${value.start}:${value.end}`,
36
36
  },
37
37
  });
38
38
  }, [filter]);
39
- const handleRange = react_1.default.useCallback((value) => {
40
- setFilterRange([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);
41
- }, [filter]);
42
- react_1.default.useEffect(() => {
43
- const handler = (event) => {
44
- setFilterValue(event.detail.value);
45
- };
46
- window.addEventListener(`@usereactify/search:filter:${filter.handle}:update`, handler);
47
- return () => window.removeEventListener(`@usereactify/search:filter:${filter.handle}:update`, handler);
48
- }, []);
49
- const reactSliderProps = (0, useReactSliderProps_1.useReactSliderProps)(filter, filterValue, filterRange, handleChange);
50
39
  const filterSliderProps = react_1.default.useMemo(() => {
51
40
  return {
52
41
  handleChange,
53
- handleRange,
54
42
  filter,
55
43
  value: filterValue,
56
- range: filterRange,
57
- reactSliderProps,
58
44
  };
59
- }, [
60
- handleChange,
61
- handleRange,
62
- filter,
63
- filterValue,
64
- filterRange,
65
- reactSliderProps,
66
- ]);
45
+ }, [filter, filterValue, handleChange]);
67
46
  return filterSliderProps;
68
47
  };
69
48
  exports.useFilterSliderProps = useFilterSliderProps;
@@ -1 +1 @@
1
- {"version":3,"file":"useFilterSliderProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterSliderProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,oCAAwC;AACxC,wCAAmC;AACnC,4EAAyE;AAElE,MAAM,oBAAoB,GAAG,CAClC,MAA0B,EAQ1B,EAAE;;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IAEjC,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,CAClD,IAAI,CAAC,KAAK,CAAC,MAAA,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,mCAAI,OAAO,CAAC,CACzD,CAAC;IACF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAmB;QACrE,CAAC,EAAE,CAAC;KACL,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,eAAK,CAAC,WAAW,CACpC,CAA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AAM,SAAS,EACpD,OAAwB,CACzB,CAAC;QAEF,OAAO,GAAG,EAAE,CACV,MAAM,CAAC,mBAAmB,CACxB,8BAA8B,MAAM,CAAC,MAAM,SAAS,EACpD,OAAwB,CACzB,CAAC;IACN,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,gBAAgB,GAAG,IAAA,yCAAmB,EAC1C,MAAM,EACN,WAAW,EACX,WAAW,EACX,YAAY,CACb,CAAC;IAEF,MAAM,iBAAiB,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC3C,OAAO;YACL,YAAY;YACZ,WAAW;YACX,MAAM;YACN,KAAK,EAAE,WAAW;YAClB,KAAK,EAAE,WAAW;YAClB,gBAAgB;SACjB,CAAC;IACJ,CAAC,EAAE;QACD,YAAY;QACZ,WAAW;QACX,MAAM;QACN,WAAW;QACX,WAAW;QACX,gBAAgB;KACjB,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAlGW,QAAA,oBAAoB,wBAkG/B","sourcesContent":["import React from \"react\";\nimport { ConfigFilterOption } from \"../types/config\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\nimport { useReactSliderProps } from \"./react-slider/useReactSliderProps\";\n\nexport const useFilterSliderProps = (\n filter: ConfigFilterOption\n): {\n filter: ConfigFilterOption;\n value: [number, number];\n range: [number, number];\n handleChange: (value: [number | string, number | string]) => void;\n handleRange: (value: [number, number]) => void;\n reactSliderProps: ReturnType<typeof useReactSliderProps>;\n} => {\n const { track } = useAnalytics();\n\n const urlSearchParam = new URLSearchParams(window.location.search);\n const [filterValue, setFilterValue] = React.useState<[number, number]>(\n JSON.parse(urlSearchParam.get(filter.handle) ?? \"[0,0]\")\n );\n const [filterRange, setFilterRange] = React.useState<[number, number]>([\n 0, 0,\n ]);\n\n const handleChange = React.useCallback(\n (value: [number | string, number | string]) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: value,\n },\n });\n\n debug.log(\"useFilterSliderProps\", \"handleChange[value]\", value);\n\n setFilterValue([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: `${value[0]}:${value[1]}`,\n },\n });\n },\n [filter]\n );\n\n const handleRange = React.useCallback(\n (value: [number | string, number | string]) => {\n setFilterRange([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);\n },\n [filter]\n );\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<{ handle: string; value: [number, number] }>\n ) => {\n setFilterValue(event.detail.value);\n };\n window.addEventListener(\n `@usereactify/search:filter:${filter.handle}:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:filter:${filter.handle}:update`,\n handler as EventListener\n );\n }, []);\n\n const reactSliderProps = useReactSliderProps(\n filter,\n filterValue,\n filterRange,\n handleChange\n );\n\n const filterSliderProps = React.useMemo(() => {\n return {\n handleChange,\n handleRange,\n filter,\n value: filterValue,\n range: filterRange,\n reactSliderProps,\n };\n }, [\n handleChange,\n handleRange,\n filter,\n filterValue,\n filterRange,\n reactSliderProps,\n ]);\n\n return filterSliderProps;\n};\n"]}
1
+ {"version":3,"file":"useFilterSliderProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterSliderProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAwC;AACxC,wCAAmC;AAE5B,MAAM,oBAAoB,GAAG,CAClC,MAA0B,EAW1B,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IACjC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,CAGjD;QACD,KAAK,EAAE,CAAC;QACR,GAAG,EAAE,CAAC;KACP,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,eAAK,CAAC,WAAW,CACpC,CAAC,KAAuD,EAAE,EAAE;QAC1D,eAAK,CAAC,UAAU,CAAC;YACf,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,uBAAuB;YAChC,IAAI,EAAE;gBACJ,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,KAAK;aACb;SACF,CAAC,CAAC;QAEH,eAAK,CAAC,GAAG,CAAC,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAEhE,cAAc,CAAC;YACb,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;YACjC,GAAG,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;SAC9B,CAAC,CAAC;QAEH,KAAK,CAAC;YACJ,SAAS,EAAE,cAAc;YACzB,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,EAAE;aACrC;SACF,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,iBAAiB,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC3C,OAAO;YACL,YAAY;YACZ,MAAM;YACN,KAAK,EAAE,WAAW;SACnB,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;IAExC,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AA7DW,QAAA,oBAAoB,wBA6D/B","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../types/config\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilterSliderProps = (\n filter: ConfigFilterOption\n): {\n filter: ConfigFilterOption;\n value: {\n start: number;\n end: number;\n };\n handleChange: (value: {\n start: number | string;\n end: number | string;\n }) => void;\n} => {\n const { track } = useAnalytics();\n const [filterValue, setFilterValue] = React.useState<{\n start: number;\n end: number;\n }>({\n start: 0,\n end: 0,\n });\n\n const handleChange = React.useCallback(\n (value: { start: number | string; end: number | string }) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: value,\n },\n });\n\n debug.log(\"useFilterSliderProps\", \"handleChange[value]\", value);\n\n setFilterValue({\n start: parseInt(`${value.start}`),\n end: parseInt(`${value.end}`),\n });\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: `${value.start}:${value.end}`,\n },\n });\n },\n [filter]\n );\n\n const filterSliderProps = React.useMemo(() => {\n return {\n handleChange,\n filter,\n value: filterValue,\n };\n }, [filter, filterValue, handleChange]);\n\n return filterSliderProps;\n};\n"]}
@@ -0,0 +1,15 @@
1
+ import { ReactivesearchResultProps } from "../types";
2
+ export declare const usePaginationLoadMore: (input: ReactivesearchResultProps) => {
3
+ loading: boolean;
4
+ hasMore: boolean;
5
+ handleLoadMore: () => void;
6
+ resultStats: {
7
+ time: number;
8
+ hidden: number;
9
+ promoted: number;
10
+ currentPage: number;
11
+ numberOfPages: number;
12
+ numberOfResults?: number;
13
+ displayedResults: number;
14
+ };
15
+ };
@@ -0,0 +1,38 @@
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
+ exports.usePaginationLoadMore = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const hooks_1 = require("../hooks");
9
+ const utility_1 = require("../utility");
10
+ const usePaginationLoadMore = (input) => {
11
+ const analyticsHook = (0, hooks_1.useAnalytics)();
12
+ const { filterStack } = (0, hooks_1.useFilters)();
13
+ const hasMore = input.resultStats.displayedResults !== input.resultStats.numberOfResults;
14
+ const handleLoadMore = react_1.default.useCallback(() => {
15
+ utility_1.debug.log("usePaginationLoadMore", "handleLoadMore");
16
+ if (!hasMore) {
17
+ return;
18
+ }
19
+ input.loadMore();
20
+ analyticsHook.track({
21
+ eventName: "paginationChange",
22
+ payload: {
23
+ page: Math.ceil(input.resultStats.displayedResults / ((filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) || 20)) + 1,
24
+ source: window.location.pathname.includes("/search")
25
+ ? "search"
26
+ : "collection",
27
+ },
28
+ });
29
+ }, [input.loadMore, analyticsHook.track, input.resultStats, filterStack]);
30
+ return react_1.default.useMemo(() => ({
31
+ loading: input.loading,
32
+ hasMore,
33
+ handleLoadMore,
34
+ resultStats: input.resultStats,
35
+ }), [input.loading, hasMore, handleLoadMore, input.resultStats]);
36
+ };
37
+ exports.usePaginationLoadMore = usePaginationLoadMore;
38
+ //# sourceMappingURL=usePaginationLoadMore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePaginationLoadMore.js","sourceRoot":"","sources":["../../../src/hooks/usePaginationLoadMore.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAoD;AACpD,wCAAmC;AAE5B,MAAM,qBAAqB,GAAG,CACnC,KAAgC,EAchC,EAAE;IACF,MAAM,aAAa,GAAG,IAAA,oBAAY,GAAE,CAAC;IACrC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,MAAM,OAAO,GACX,KAAK,CAAC,WAAW,CAAC,gBAAgB,KAAK,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC;IAE3E,MAAM,cAAc,GAAG,eAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,eAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE,gBAAgB,CAAC,CAAC;QAErD,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QAED,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,aAAa,CAAC,KAAK,CAAC;YAClB,SAAS,EAAE,kBAAkB;YAC7B,OAAO,EAAE;gBACP,IAAI,EACF,IAAI,CAAC,IAAI,CACP,KAAK,CAAC,WAAW,CAAC,gBAAgB,GAAG,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,KAAI,EAAE,CAAC,CACnE,GAAG,CAAC;gBACP,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAClD,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,YAAY;aACjB;SACF,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1E,OAAO,eAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO;QACP,cAAc;QACd,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC,EACF,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,WAAW,CAAC,CAC5D,CAAC;AACJ,CAAC,CAAC;AArDW,QAAA,qBAAqB,yBAqDhC","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchResultProps } from \"../types\";\nimport { useAnalytics, useFilters } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const usePaginationLoadMore = (\n input: ReactivesearchResultProps\n): {\n loading: boolean;\n hasMore: boolean;\n handleLoadMore: () => void;\n resultStats: {\n time: number;\n hidden: number;\n promoted: number;\n currentPage: number;\n numberOfPages: number;\n numberOfResults?: number;\n displayedResults: number;\n };\n} => {\n const analyticsHook = useAnalytics();\n const { filterStack } = useFilters();\n\n const hasMore =\n input.resultStats.displayedResults !== input.resultStats.numberOfResults;\n\n const handleLoadMore = React.useCallback(() => {\n debug.log(\"usePaginationLoadMore\", \"handleLoadMore\");\n\n if (!hasMore) {\n return;\n }\n\n input.loadMore();\n analyticsHook.track({\n eventName: \"paginationChange\",\n payload: {\n page:\n Math.ceil(\n input.resultStats.displayedResults / (filterStack?.pageSize || 20)\n ) + 1,\n source: window.location.pathname.includes(\"/search\")\n ? \"search\"\n : \"collection\",\n },\n });\n }, [input.loadMore, analyticsHook.track, input.resultStats, filterStack]);\n\n return React.useMemo(\n () => ({\n loading: input.loading,\n hasMore,\n handleLoadMore,\n resultStats: input.resultStats,\n }),\n [input.loading, hasMore, handleLoadMore, input.resultStats]\n );\n};\n"]}