@sledge-app/react-instant-search 2.0.67 → 2.0.69

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.
@@ -1807,6 +1807,19 @@ const checkWishlist = async ({ id, variantId = "", query = null }) => {
1807
1807
  return;
1808
1808
  });
1809
1809
  };
1810
+ const checkWishlists = async () => {
1811
+ let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1812
+ let url = `${API_URL}/wishlist/checks`;
1813
+ return await fetchApi({
1814
+ url,
1815
+ method: "GET",
1816
+ authorization: sledgeAuthApp
1817
+ }).then((result) => {
1818
+ return result;
1819
+ }).catch(() => {
1820
+ return;
1821
+ });
1822
+ };
1810
1823
  const clearWishlist = async () => {
1811
1824
  let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1812
1825
  let url = `${API_URL}/wishlist/clear`;
@@ -3308,6 +3321,27 @@ const BadgeInitSelector = (props) => {
3308
3321
  });
3309
3322
  }
3310
3323
  };
3324
+ let wishlistBatchCache = null;
3325
+ let wishlistBatchPromise = null;
3326
+ const fetchWishlistBatch = async () => {
3327
+ if (wishlistBatchCache)
3328
+ return wishlistBatchCache;
3329
+ if (!wishlistBatchPromise) {
3330
+ wishlistBatchPromise = checkWishlists().then((result) => {
3331
+ wishlistBatchCache = result;
3332
+ wishlistBatchPromise = null;
3333
+ return result;
3334
+ }).catch(() => {
3335
+ wishlistBatchPromise = null;
3336
+ return;
3337
+ });
3338
+ }
3339
+ return wishlistBatchPromise;
3340
+ };
3341
+ const clearWishlistBatchCache = () => {
3342
+ wishlistBatchCache = null;
3343
+ wishlistBatchPromise = null;
3344
+ };
3311
3345
  const Trigger = (props) => {
3312
3346
  var _a, _b, _c, _d, _e;
3313
3347
  const {
@@ -3358,7 +3392,8 @@ const Trigger = (props) => {
3358
3392
  const { show: show_notification, location: location_notification } = ((_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.notification) || {};
3359
3393
  const { title_added_to_wishlist, text_added_to_wishlist, title_removed_to_wishlist, text_removed_to_wishlist, title_fail_add_to_wishlist, text_fail_add_to_wishlist } = ((_d = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _d.notification) || {};
3360
3394
  const { alert_login, alert, login_button } = ((_e = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _e.widget) || {};
3361
- const handleCheckWishlist = async () => {
3395
+ const handleCheckWishlist = async (props2) => {
3396
+ const { useBatch = true } = props2 || {};
3362
3397
  let response;
3363
3398
  let queryParam = {
3364
3399
  ...wishlistPreviewSettings && (generalPreviewSettings == null ? void 0 : generalPreviewSettings.use_dummy_data) ? {
@@ -3369,11 +3404,23 @@ const Trigger = (props) => {
3369
3404
  response = wishlistChecked;
3370
3405
  setIsFirstTime(false);
3371
3406
  } else {
3372
- response = await checkWishlist({
3373
- id: productId,
3374
- variantId: productVariantId,
3375
- query: queryParam
3376
- });
3407
+ if (useBatch && !reload && !wishlistPreviewSettings && !(generalPreviewSettings == null ? void 0 : generalPreviewSettings.use_dummy_data)) {
3408
+ const batchResponse = await fetchWishlistBatch();
3409
+ const { status, data } = batchResponse || {};
3410
+ if ((status == null ? void 0 : status.code) === 200 && data) {
3411
+ const productIdValue = productId ? String(productId) : "";
3412
+ const variantIdValue = productVariantId ? String(productVariantId) : "";
3413
+ const productWishlist = productIdValue ? (data == null ? void 0 : data[productIdValue]) || {} : {};
3414
+ response = Boolean((productWishlist == null ? void 0 : productWishlist.all) || variantIdValue && (productWishlist == null ? void 0 : productWishlist[variantIdValue]));
3415
+ }
3416
+ }
3417
+ if (typeof response === "undefined") {
3418
+ response = await checkWishlist({
3419
+ id: productId,
3420
+ variantId: productVariantId,
3421
+ query: queryParam
3422
+ });
3423
+ }
3377
3424
  }
3378
3425
  setIsWishlist(forceActive ? forceActive : response);
3379
3426
  };
@@ -3411,6 +3458,7 @@ const Trigger = (props) => {
3411
3458
  });
3412
3459
  if (run) {
3413
3460
  setIsWishlist(!isWishlist);
3461
+ clearWishlistBatchCache();
3414
3462
  if (triggerRenderWishlistBadge)
3415
3463
  triggerRenderWishlistBadge(true);
3416
3464
  if (isJsVersion) {
@@ -3432,8 +3480,6 @@ const Trigger = (props) => {
3432
3480
  if (window.sledgeWishlistButtonDetailUpdate)
3433
3481
  window.sledgeWishlistButtonDetailUpdate();
3434
3482
  }
3435
- if (!wishlistPreviewSettings)
3436
- handleCheckWishlist();
3437
3483
  if (!isWishlist) {
3438
3484
  handleFunctions.onAfterAddWishlist && handleFunctions.onAfterAddWishlist("success");
3439
3485
  } else {
@@ -6880,8 +6926,8 @@ const keyOpenFilters = ({ items = [] }) => {
6880
6926
  }).filter((item) => item) : [];
6881
6927
  };
6882
6928
  const handleSearchResponse = async (props) => {
6883
- var _a, _b, _c;
6884
- const {
6929
+ var _a, _b, _c, _d;
6930
+ let {
6885
6931
  layoutType = "default",
6886
6932
  clickedTabIndexId,
6887
6933
  clickedTabIndexType = "product",
@@ -6910,6 +6956,7 @@ const handleSearchResponse = async (props) => {
6910
6956
  instantSearchSettings
6911
6957
  } = props;
6912
6958
  let keyword = keywordProp;
6959
+ let collectionIdSelected = collectionId || (instantSearchSettings == null ? void 0 : instantSearchSettings.collections_all_id) || "";
6913
6960
  const isResultForProduct = clickedTabIndexType === "product";
6914
6961
  const isTypeCategoryHasPublished = ({ usePublishedFilter: usePublishedFilter2, type }) => Boolean(usePublishedFilter2 && type && ["collection", "page", "article"].includes(type));
6915
6962
  const { separator: hierarchical_separator, hiddens: hierarchical_hiddens } = hierarchicalProductTypeSettings || {};
@@ -6930,6 +6977,11 @@ const handleSearchResponse = async (props) => {
6930
6977
  containsFilter = `(${searchableAttributes.map((item) => `'${item}' CONTAINS ${JSON.stringify(keywordProp)}`).join(" OR ")})`;
6931
6978
  keyword = "";
6932
6979
  }
6980
+ let merchandisingSettings = null;
6981
+ if (collectionIdSelected && ((_d = instantSearchSettings == null ? void 0 : instantSearchSettings.have_merchandising_settings) == null ? void 0 : _d[collectionIdSelected])) {
6982
+ sort.push(`merchandising.${collectionIdSelected}.demote:asc`);
6983
+ merchandisingSettings = `merchandising.${collectionIdSelected}.hide != 1`;
6984
+ }
6933
6985
  let response;
6934
6986
  let filterProduct = createQueryFilter({
6935
6987
  facets,
@@ -6953,7 +7005,8 @@ const handleSearchResponse = async (props) => {
6953
7005
  (hiddenTags == null ? void 0 : hiddenTags.length) ? `'tags' NOT IN ${JSON.stringify(hiddenTags)}` : null,
6954
7006
  collectionId ? `'collections.id' = '${collectionId}'` : null,
6955
7007
  !showOutOfStock ? `'availability' IN ${JSON.stringify(["in stock"])}` : null,
6956
- containsFilter
7008
+ containsFilter,
7009
+ merchandisingSettings
6957
7010
  ],
6958
7011
  allowedFilterSlider,
6959
7012
  hierarchicalFacetAliases,
@@ -10716,14 +10769,22 @@ const ResultProduct = React__default.memo((props) => {
10716
10769
  let sort = soldProductAtEnd ? ["availability:asc"] : [];
10717
10770
  if (clickedSortId)
10718
10771
  sort.push(clickedSortId);
10719
- if (collectionDefaultSortBy && ((_a2 = sort == null ? void 0 : sort.some) == null ? void 0 : _a2.call(sort, (item) => item.includes("featuredSort."))) && (instantSearchSettings == null ? void 0 : instantSearchSettings.featured_as_collection_default_sort)) {
10720
- const sortMap = getSortMap({
10721
- activeCollectionId: collectionId,
10722
- collectionAllId: instantSearchSettings == null ? void 0 : instantSearchSettings.collections_all_id
10723
- });
10772
+ if ((_a2 = sort == null ? void 0 : sort.some) == null ? void 0 : _a2.call(sort, (item) => item.includes("featuredSort."))) {
10724
10773
  sort = sort.map((item) => {
10774
+ var _a3;
10725
10775
  if (item.includes("featuredSort.")) {
10726
- return sortMap[collectionDefaultSortBy];
10776
+ if (collectionDefaultSortBy && (instantSearchSettings == null ? void 0 : instantSearchSettings.featured_as_collection_default_sort)) {
10777
+ const sortMap = getSortMap({
10778
+ activeCollectionId: collectionId,
10779
+ collectionAllId: instantSearchSettings == null ? void 0 : instantSearchSettings.collections_all_id
10780
+ });
10781
+ return sortMap[collectionDefaultSortBy];
10782
+ } else {
10783
+ const collectionIdSelected = collectionId || (instantSearchSettings == null ? void 0 : instantSearchSettings.collections_all_id) || "";
10784
+ if (collectionIdSelected && ((_a3 = instantSearchSettings == null ? void 0 : instantSearchSettings.have_merchandising_settings) == null ? void 0 : _a3[collectionIdSelected])) {
10785
+ return `merchandising.${collectionIdSelected}.position:asc`;
10786
+ }
10787
+ }
10727
10788
  }
10728
10789
  return item;
10729
10790
  });