@sledge-app/react-instant-search 0.0.75 → 0.0.76

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.
@@ -6,7 +6,7 @@ const ProductFilterWidget = (props) => {
6
6
  return /* @__PURE__ */ jsxRuntimeExports.jsx(SearchResultWidget, { layoutType: "product-filter", ...props });
7
7
  };
8
8
  const API_URL = "https://sledge-api-preprod.offstack.io";
9
- const INSTANT_SEARCH_ENGINE_URL = "http://localhost:7700";
9
+ const INSTANT_SEARCH_ENGINE_URL = "https://instant-search-engine.offstack.io";
10
10
  const LOCAL_STORAGE_KEY = {
11
11
  ANONYM_ID: "sledge-anonym-id",
12
12
  AUTH_APP: "sledge-auth-app",
@@ -1564,8 +1564,8 @@ const WidgetHeader = (props) => {
1564
1564
  WidgetHeader.Sort = WidgetHeaderSort;
1565
1565
  WidgetHeader.AddTrigger = WidgetHeaderAddTrigger;
1566
1566
  WidgetHeader.Summary = WidgetHeaderSummary;
1567
- const fetchApi = async (url, method, body, token) => {
1568
- let sledgeInstantSearchAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP);
1567
+ const fetchApi = async (url, method, body) => {
1568
+ let sledgeInstantSearchAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP);
1569
1569
  var myHeaders = new Headers();
1570
1570
  myHeaders.append("Authorization", `Bearer ${sledgeInstantSearchAuthApp}`);
1571
1571
  myHeaders.append("Content-Type", "application/json");
@@ -1586,8 +1586,8 @@ const fetchApi = async (url, method, body, token) => {
1586
1586
  const search = async (index, body) => {
1587
1587
  return await fetchApi(`/indexes/${index}/search`, "POST", body);
1588
1588
  };
1589
- const multiSearch = async (body, token) => {
1590
- return await fetchApi("/multi-search", "POST", body, token);
1589
+ const multiSearch = async (body) => {
1590
+ return await fetchApi("/multi-search", "POST", body);
1591
1591
  };
1592
1592
  const searchTrigger = async (data) => {
1593
1593
  const { keyword, resultCount } = data;
@@ -1673,8 +1673,7 @@ const ProductGrid = ({
1673
1673
  onAfterRenderProduct,
1674
1674
  showPopupComponent,
1675
1675
  setShowPopupComponent,
1676
- dataReviews,
1677
- dataWishlists
1676
+ dataReviews
1678
1677
  }) => {
1679
1678
  const {
1680
1679
  show_vendor = true,
@@ -1788,8 +1787,7 @@ const ProductGrid = ({
1788
1787
  },
1789
1788
  ...triggerPropAdditional,
1790
1789
  onAfterAddWishlist,
1791
- onAfterRemoveWishlist,
1792
- wishlistChecked: dataWishlists == null ? void 0 : dataWishlists[id]
1790
+ onAfterRemoveWishlist
1793
1791
  }
1794
1792
  ),
1795
1793
  /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: (image == null ? void 0 : image.src) || "", alt: "sledge-product-card-image", loading: "lazy", onError: (event) => event.currentTarget.src = `${API_URL}/img/blank-image.png` })
@@ -2666,9 +2664,9 @@ const SearchIconWidgetPopup = () => {
2666
2664
  ] }) });
2667
2665
  };
2668
2666
  const SearchResultWidget = (props) => {
2669
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2667
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2670
2668
  const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
2671
- const { layoutType = "default", query, params, children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct, data: propsData } = props;
2669
+ const { layoutType = "default", query, params, children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
2672
2670
  const { keyword: queryKeyword = "" } = query || {};
2673
2671
  const { collectionId } = params || {};
2674
2672
  let productCardsComponent = null;
@@ -2679,7 +2677,6 @@ const SearchResultWidget = (props) => {
2679
2677
  productCardsComponent = productCard;
2680
2678
  }
2681
2679
  });
2682
- const [settings] = React__default.useState(typeof localStorage !== "undefined" ? (_a = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "{}")) == null ? void 0 : _a.data : {});
2683
2680
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
2684
2681
  const [isLoading, setIsLoading] = React__default.useState(true);
2685
2682
  const [keyword, setKeyword] = React__default.useState("");
@@ -2698,7 +2695,6 @@ const SearchResultWidget = (props) => {
2698
2695
  const [colorSwatches, setColorSwatches] = React__default.useState([]);
2699
2696
  const [defaultSort, setDefaultSort] = React__default.useState("");
2700
2697
  const [showOutOfStock, setShowOutOfStock] = React__default.useState(false);
2701
- const [initStatesFirstTime, setInitStatesFirstTime] = React__default.useState(true);
2702
2698
  const searchResultContainerRef = React__default.useRef(null);
2703
2699
  const previousState = usePrevious({ keyword });
2704
2700
  const handleChangeTabIndex = (id, name, e) => {
@@ -2746,12 +2742,7 @@ const SearchResultWidget = (props) => {
2746
2742
  };
2747
2743
  })
2748
2744
  };
2749
- if (propsData && initStatesFirstTime) {
2750
- response = propsData.result;
2751
- setInitStatesFirstTime(false);
2752
- response = await multiSearch(body);
2753
- } else
2754
- response = await multiSearch(body);
2745
+ response = await multiSearch(body);
2755
2746
  if (!response)
2756
2747
  return;
2757
2748
  const { results } = response;
@@ -2848,8 +2839,8 @@ const SearchResultWidget = (props) => {
2848
2839
  }
2849
2840
  }, [keyword]);
2850
2841
  const tabSkeleton = layoutType === "default" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-tab-list sledge-instant-search__result-tab-list-skeleton", children: [1, 2, 3, 4, 5].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "122px", height: "28px", rounded: "md", color: "grey-100", animationDuration: "15s" }, index)) }) : null;
2851
- const filterHorizontalSkeleton = ((_b = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _b.enable_on_search) && ((_c = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _c.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-skeleton", children: [1, 2, 3, 4, 5, 6, 7].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "106px", height: "42px", rounded: "md", color: "grey-100", animationDuration: "13s" }, index)) }) : null;
2852
- const filterVerticalSkeleton = ((_d = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _d.enable_on_search) && ((_e = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _e.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2842
+ const filterHorizontalSkeleton = ((_a = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a.enable_on_search) && ((_b = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _b.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-skeleton", children: [1, 2, 3, 4, 5, 6, 7].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "106px", height: "42px", rounded: "md", color: "grey-100", animationDuration: "13s" }, index)) }) : null;
2843
+ const filterVerticalSkeleton = ((_c = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _c.enable_on_search) && ((_d = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _d.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2853
2844
  /* @__PURE__ */ jsxRuntimeExports.jsxs(
2854
2845
  "div",
2855
2846
  {
@@ -3065,7 +3056,7 @@ const SearchResultWidget = (props) => {
3065
3056
  )
3066
3057
  ] }) : null;
3067
3058
  const productGridSkeleton = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3068
- ((_f = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _f.show_total_products) && ((_g = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _g.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsx(
3059
+ ((_e = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _e.show_total_products) && ((_f = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _f.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsx(
3069
3060
  SkeletonLoading.Item,
3070
3061
  {
3071
3062
  width: "117px",
@@ -3081,7 +3072,7 @@ const SearchResultWidget = (props) => {
3081
3072
  /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.ProductGrid, { count: 12, type: "large" })
3082
3073
  ] });
3083
3074
  const searchAndSelectOptionSkeleton = /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-keyword", children: [
3084
- ((_h = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _h.show_total_products) && ((_i = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _i.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary sledge-instant-search__result-data-summary-filter-horizontal", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "117px", height: "28px", color: "grey-100", rounded: "md", animationDuration: "13s" }) }) : null,
3075
+ ((_g = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _g.show_total_products) && ((_h = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _h.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary sledge-instant-search__result-data-summary-filter-horizontal", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "117px", height: "28px", color: "grey-100", rounded: "md", animationDuration: "13s" }) }) : null,
3085
3076
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-keyword-form", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
3086
3077
  SkeletonLoading.Item,
3087
3078
  {
@@ -3108,11 +3099,11 @@ const SearchResultWidget = (props) => {
3108
3099
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-tab-total", children: total || 0 })
3109
3100
  ] }, index);
3110
3101
  }) }) : null }),
3111
- isFirstLoading && (layoutType == null ? void 0 : layoutType.length) && !propsData ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3102
+ isFirstLoading && (layoutType == null ? void 0 : layoutType.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3112
3103
  tabSkeleton,
3113
3104
  filterHorizontalSkeleton,
3114
3105
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-wrapper sledge-instant-search__result-wrapper-skeleton", children: [
3115
- ((_j = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _j.enable_on_search) && ((_k = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _k.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter", children: filterVerticalSkeleton }) : null,
3106
+ ((_i = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _i.enable_on_search) && ((_j = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _j.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter", children: filterVerticalSkeleton }) : null,
3116
3107
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data", children: [
3117
3108
  searchAndSelectOptionSkeleton,
3118
3109
  productGridSkeleton
@@ -3147,9 +3138,7 @@ const SearchResultWidget = (props) => {
3147
3138
  filterVerticalSkeleton,
3148
3139
  productGridSkeleton,
3149
3140
  searchAndSelectOptionSkeleton,
3150
- searchResultContainerRef,
3151
- data: propsData,
3152
- settings
3141
+ searchResultContainerRef
3153
3142
  })
3154
3143
  ] });
3155
3144
  };
@@ -3181,9 +3170,7 @@ const ResultProduct = (props) => {
3181
3170
  onAfterAddWishlist,
3182
3171
  onAfterRemoveWishlist,
3183
3172
  onAfterRenderProduct,
3184
- searchResultContainerRef,
3185
- data: propsData,
3186
- settings
3173
+ searchResultContainerRef
3187
3174
  } = props || {};
3188
3175
  const { keyword: queryKeyword = "" } = query || {};
3189
3176
  const { collectionId } = params || {};
@@ -3210,7 +3197,6 @@ const ResultProduct = (props) => {
3210
3197
  const [allowedFilter, setAllowedFilter] = React__default.useState([]);
3211
3198
  const [isFilterChanged, setIsFilterChanged] = React__default.useState(false);
3212
3199
  const [summaryText, setSummaryText] = React__default.useState(null);
3213
- const [handleSearchResultFirstTime, setHandleSearchResultFirstTime] = React__default.useState(true);
3214
3200
  const previousState = usePrevious({ keyword, clickedLimitId, clickedFacets });
3215
3201
  const { color: filter_title_color, font_size: filter_title_font_size, font_weight: filter_title_font_weight, text_transform: filter_title_text_transform } = ((_c = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _c.title) || {};
3216
3202
  const {
@@ -3384,7 +3370,6 @@ const ResultProduct = (props) => {
3384
3370
  );
3385
3371
  };
3386
3372
  const handleSearchResult = async (isRefreshPage = false, onSearch = false) => {
3387
- var _a2, _b2;
3388
3373
  if (!clickedTabIndexId)
3389
3374
  return;
3390
3375
  if (isRefreshPage)
@@ -3393,13 +3378,13 @@ const ResultProduct = (props) => {
3393
3378
  let detectClickedFacets = detectQueryStringFilter(clickedFacets);
3394
3379
  let response;
3395
3380
  let filters = Object.entries(detectClickedFacets).map((facet) => {
3396
- var _a3, _b3;
3381
+ var _a2, _b2;
3397
3382
  if ((facet == null ? void 0 : facet.length) && facet[1].length) {
3398
3383
  let value = facet[0];
3399
3384
  let isCustom = ["variants.inventory_quantity"].includes(value);
3400
3385
  let isRange = ["variants.price"].includes(value);
3401
3386
  let isArray = ["tags"].includes(value);
3402
- let items = Array.isArray(facet[1]) && ((_a3 = facet[1]) == null ? void 0 : _a3.length) > 1 ? isRange ? `${value} >= ${facet[1][0]} AND ${value} <= ${facet[1][1]}` : isArray ? `${value} IN [${facet[1]}]` : (_b3 = facet[1]) == null ? void 0 : _b3.map((item) => {
3387
+ let items = Array.isArray(facet[1]) && ((_a2 = facet[1]) == null ? void 0 : _a2.length) > 1 ? isRange ? `${value} >= ${facet[1][0]} AND ${value} <= ${facet[1][1]}` : isArray ? `${value} IN [${facet[1]}]` : (_b2 = facet[1]) == null ? void 0 : _b2.map((item) => {
3403
3388
  return isCustom ? `${value} ${item}` : `${value} = '${item}'`;
3404
3389
  }).join(" OR ") : isCustom ? `${value} ${facet[1]}` : isArray ? `${value} IN [${facet[1]}]` : `${value} = '${facet[1]}'`;
3405
3390
  return items;
@@ -3418,11 +3403,7 @@ const ResultProduct = (props) => {
3418
3403
  facets,
3419
3404
  filter: filters.join(" AND ")
3420
3405
  };
3421
- if (propsData && handleSearchResultFirstTime) {
3422
- response = (_b2 = (_a2 = propsData == null ? void 0 : propsData.result) == null ? void 0 : _a2.results) == null ? void 0 : _b2[0];
3423
- setHandleSearchResultFirstTime(false);
3424
- } else
3425
- response = await search(clickedTabIndexId, body);
3406
+ response = await search(clickedTabIndexId, body);
3426
3407
  handleSearchResultData(response, onSearch);
3427
3408
  };
3428
3409
  const handleAllowedFilter = () => {
@@ -3668,7 +3649,7 @@ const ResultProduct = (props) => {
3668
3649
  });
3669
3650
  const paginationComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(Pagination, { currentPage, totalPage, totalResult: totalSearchResult, onChange: (page) => handlePageChange(page) });
3670
3651
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3671
- ((_f = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _f.enable_on_search) && ((_g = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _g.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isFirstLoading && !propsData ? filterHorizontalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isLoadingSetting && !propsData ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-loading", children: filterHorizontalSkeleton }) : filterHorizontalComponents.every((currentValue) => !currentValue) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal-wrapper", children: [
3652
+ ((_f = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _f.enable_on_search) && ((_g = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _g.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isFirstLoading ? filterHorizontalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isLoadingSetting ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-loading", children: filterHorizontalSkeleton }) : filterHorizontalComponents.every((currentValue) => !currentValue) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal-wrapper", children: [
3672
3653
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal", children: filterHorizontalComponents }),
3673
3654
  Boolean((dataClickedFacets == null ? void 0 : dataClickedFacets.length) && ((_h = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _h.show_refine_by_block)) ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: Boolean(dataClickedFacets.every((currentValue) => !currentValue)) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal", children: [
3674
3655
  /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -3746,7 +3727,7 @@ const ResultProduct = (props) => {
3746
3727
  value
3747
3728
  };
3748
3729
  }),
3749
- value: clickedSortId || (settings == null ? void 0 : settings.default_sort),
3730
+ value: clickedSortId,
3750
3731
  onChange: ({ label, value }) => handleChangeSort(label, value)
3751
3732
  }
3752
3733
  )
@@ -3799,9 +3780,7 @@ const ResultProduct = (props) => {
3799
3780
  onAfterAddToCart,
3800
3781
  onAfterAddWishlist,
3801
3782
  onAfterRemoveWishlist,
3802
- onAfterRenderProduct,
3803
- dataWishlists: propsData == null ? void 0 : propsData.wishlists,
3804
- dataReviews: propsData == null ? void 0 : propsData.reviews
3783
+ onAfterRenderProduct
3805
3784
  }
3806
3785
  ),
3807
3786
  paginationComponent