@sledge-app/react-instant-search 1.0.48 → 1.0.49

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.
@@ -1320,6 +1320,12 @@ const Trigger = (props) => {
1320
1320
  });
1321
1321
  const [isRequiredLogin, setIsRequiredLogin] = React__default.useState(false);
1322
1322
  const [isFirstTime, setIsFirstTime] = React__default.useState(true);
1323
+ const [hasEntry, setHasEntry] = React__default.useState(false);
1324
+ const [rootRef, rootEntry] = useIntersectionObserver({
1325
+ threshold: 0,
1326
+ root: null,
1327
+ rootMargin: "0px"
1328
+ });
1323
1329
  const { is_required_login } = ((_b = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _b.global) || {};
1324
1330
  const { show: show_notification, location: location_notification } = ((_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.notification) || {};
1325
1331
  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) || {};
@@ -1402,7 +1408,11 @@ const Trigger = (props) => {
1402
1408
  setIsLoading(false);
1403
1409
  };
1404
1410
  React__default.useEffect(() => {
1405
- if (!isRenderAppWishlist)
1411
+ if (!hasEntry && (rootEntry == null ? void 0 : rootEntry.isIntersecting))
1412
+ setHasEntry(rootEntry == null ? void 0 : rootEntry.isIntersecting);
1413
+ }, [rootEntry]);
1414
+ React__default.useEffect(() => {
1415
+ if (!isRenderAppWishlist || !hasEntry)
1406
1416
  return;
1407
1417
  if (typeof window !== "undefined") {
1408
1418
  window.sledgeWishlistTriggerUpdate = () => {
@@ -1410,15 +1420,15 @@ const Trigger = (props) => {
1410
1420
  };
1411
1421
  }
1412
1422
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
1413
- }, [isRenderAppWishlist]);
1423
+ }, [isRenderAppWishlist, hasEntry]);
1414
1424
  React__default.useEffect(() => {
1415
1425
  setIsRequiredLogin(sledgeAnonymId && is_required_login);
1416
1426
  }, [sledgeAnonymId]);
1417
1427
  React__default.useEffect(() => {
1418
- if (!isRenderAppWishlist)
1428
+ if (!isRenderAppWishlist || !hasEntry)
1419
1429
  return;
1420
1430
  handleCheckWishlist();
1421
- }, [isRenderAppWishlist, productVariantId]);
1431
+ }, [isRenderAppWishlist, hasEntry, productVariantId]);
1422
1432
  const isActive = (isWishlist || forceActive) && !isRequiredLogin;
1423
1433
  React__default.useEffect(() => {
1424
1434
  if (isActive) {
@@ -1429,7 +1439,7 @@ const Trigger = (props) => {
1429
1439
  setTypeIcon(defaultTypeIcon);
1430
1440
  }
1431
1441
  }, [isWishlist]);
1432
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !isLoading && !hidden && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-wishlist__trigger-block", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1442
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: rootRef, children: !isLoading && !hidden && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-wishlist__trigger-block", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1433
1443
  "span",
1434
1444
  {
1435
1445
  className: "sledge-wishlist__trigger",
@@ -1896,7 +1906,13 @@ const Rating = (props) => {
1896
1906
  const [averageReview, setAverageReview] = React__default.useState(((_b = propsData == null ? void 0 : propsData.rating) == null ? void 0 : _b.average) || average || "0");
1897
1907
  const [dataSettings, setDataSettings] = React__default.useState((sledgeSettings == null ? void 0 : sledgeSettings.review) || {});
1898
1908
  const [isFirstTime, setIsFirstTime] = React__default.useState(true);
1909
+ const [hasEntry, setHasEntry] = React__default.useState(false);
1899
1910
  const previousState = usePrevious({ productId });
1911
+ const [rootRef, rootEntry] = useIntersectionObserver({
1912
+ threshold: 0,
1913
+ root: null,
1914
+ rootMargin: "0px"
1915
+ });
1900
1916
  const { fill_color = "#23BC45", outline_color = "#8D9196" } = ((_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.rating) || {};
1901
1917
  const unixTimestamp = getUnixTimestamp();
1902
1918
  const handleProductRatingInfo = async (paramsProductId, isTriggerMultiComponent = false) => {
@@ -1961,7 +1977,11 @@ const Rating = (props) => {
1961
1977
  }, 200);
1962
1978
  };
1963
1979
  React__default.useEffect(() => {
1964
- if (!isRenderAppProductReview)
1980
+ if (!hasEntry && (rootEntry == null ? void 0 : rootEntry.isIntersecting))
1981
+ setHasEntry(rootEntry == null ? void 0 : rootEntry.isIntersecting);
1982
+ }, [rootEntry]);
1983
+ React__default.useEffect(() => {
1984
+ if (!isRenderAppProductReview || !hasEntry)
1965
1985
  return;
1966
1986
  if (size === "xs") {
1967
1987
  setSizing({
@@ -1983,7 +2003,7 @@ const Rating = (props) => {
1983
2003
  if (isProductIdChanged)
1984
2004
  setIsFirstLoading(true);
1985
2005
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null);
1986
- }, [isRenderAppProductReview, productId]);
2006
+ }, [isRenderAppProductReview, hasEntry, productId]);
1987
2007
  React__default.useEffect(() => {
1988
2008
  if (!productId || productId && valueRenderProductReviewRating !== productId)
1989
2009
  return;
@@ -2000,6 +2020,7 @@ const Rating = (props) => {
2000
2020
  ...typeof size === "string" ? {
2001
2021
  ["data-rating-size"]: size
2002
2022
  } : {},
2023
+ ref: rootRef,
2003
2024
  children: isFirstLoading && withSkeletonLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "230px", height: "28px", color: "lighten", rounded: "md" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !isLoading && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2004
2025
  [1, 2, 3, 4, 5].map((item, index) => {
2005
2026
  if (!(item <= numberOfIcons))
@@ -2509,6 +2530,16 @@ const ProductCard = (props) => {
2509
2530
  const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
2510
2531
  const [selectedVariantId, setSelectedVariantId] = React__default.useState(defaultSelectedVariantId);
2511
2532
  const [selectedVariantStock, setSelectedVariantStock] = React__default.useState(defaultSelectedVariantStock);
2533
+ const [hasEntry, setHasEntry] = React__default.useState(false);
2534
+ const [rootRef, rootEntry] = useIntersectionObserver({
2535
+ threshold: 0,
2536
+ root: null,
2537
+ rootMargin: "0px"
2538
+ });
2539
+ React__default.useEffect(() => {
2540
+ if (!hasEntry && (rootEntry == null ? void 0 : rootEntry.isIntersecting))
2541
+ setHasEntry(rootEntry == null ? void 0 : rootEntry.isIntersecting);
2542
+ }, [rootEntry]);
2512
2543
  let isLoadingAddToCart = clickedAddToCartId == selectedVariantId;
2513
2544
  let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !Number(selectedVariantStock) && showOptionOutOfStock : false;
2514
2545
  let component = null;
@@ -2536,7 +2567,7 @@ const ProductCard = (props) => {
2536
2567
  setShowPopupComponent,
2537
2568
  sourceApp
2538
2569
  };
2539
- component = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isComponentJsVersion ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: CardsComponent({ ...CardsProps }) } }) : /* @__PURE__ */ jsxRuntimeExports.jsx(CardsComponent, { ...CardsProps }) });
2570
+ component = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isComponentJsVersion ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-entry-card", dangerouslySetInnerHTML: { __html: CardsComponent({ ...CardsProps }) } }) : /* @__PURE__ */ jsxRuntimeExports.jsx(CardsComponent, { ...CardsProps }) });
2540
2571
  } else {
2541
2572
  let setDefaultFunction = function() {
2542
2573
  if (!(variants == null ? void 0 : variants.length))
@@ -2811,7 +2842,7 @@ ${selectedOption === item2 ? "sledge__product-variant-size-swatch-active" : ""}
2811
2842
  ) }) : null
2812
2843
  ] });
2813
2844
  }
2814
- return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
2845
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-entry-card", ref: rootRef, children: hasEntry && component }, id);
2815
2846
  };
2816
2847
  const ProductGrid = (props) => {
2817
2848
  const { type, className = "", data, setting, sourceApp = null, useSlider = false, onAfterAddToCart, onAfterRenderProduct } = props;