@sledge-app/react-instant-search 0.0.89 → 0.0.91
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.
- package/dist/components/ProductFilterWidget/ProductFilterWidgetInitSelector.d.ts.map +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidgetInitSelector.d.ts.map +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidgetPopup.d.ts.map +1 -1
- package/dist/components/SearchResultWidget/SearchResultWidgetInitSelector.d.ts.map +1 -1
- package/dist/components/SearchWidget/SearchWidgetInitSelector.d.ts.map +1 -1
- package/dist/sledge-react-instant-search.cjs +1 -1
- package/dist/sledge-react-instant-search.cjs.map +1 -1
- package/dist/sledge-react-instant-search.js +166 -56
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -33,7 +33,8 @@ const DATASET_ATTRIBUTE_KEY = {
|
|
|
33
33
|
ICON_SIZE: "data-icon-size",
|
|
34
34
|
API_KEY: "data-api-key",
|
|
35
35
|
INSTANT_SEARCH_API_KEY: "data-instant-search-api-key",
|
|
36
|
-
RENDER_PRODUCT_CARD: "data-render-product-card"
|
|
36
|
+
RENDER_PRODUCT_CARD: "data-render-product-card",
|
|
37
|
+
WITH_SKELETON_LOADING: "data-with-skeleton-loading"
|
|
37
38
|
},
|
|
38
39
|
WISHLIST: {
|
|
39
40
|
SHARE_ID: "data-share-id",
|
|
@@ -43,7 +44,9 @@ const DATASET_ATTRIBUTE_KEY = {
|
|
|
43
44
|
USE_PROXY_URL: "data-use-proxy-url"
|
|
44
45
|
},
|
|
45
46
|
PRODUCT_REVIEW: {
|
|
46
|
-
RATING_SIZE: "data-rating-size"
|
|
47
|
+
RATING_SIZE: "data-rating-size",
|
|
48
|
+
RATING_TOTAL: "data-rating-total",
|
|
49
|
+
RATING_AVERAGE: "data-rating-average"
|
|
47
50
|
},
|
|
48
51
|
INSTANT_SEARCH: {
|
|
49
52
|
QUERY_KEYWORD: "data-query-keyword",
|
|
@@ -65,6 +68,7 @@ const INTERNAL_SELECTOR_VALUE = {
|
|
|
65
68
|
ELEMENT_TOAST_NOTIFICATION: "toast-notification",
|
|
66
69
|
ELEMENT_CONFIRMATION_POPUP: "confirmation-popup",
|
|
67
70
|
ELEMENT_INFO_POPUP: "info-popup",
|
|
71
|
+
ELEMENT_CONTAINER_WIDGET: "container-widget",
|
|
68
72
|
WISHLIST: {
|
|
69
73
|
ELEMENT_BADGE_FLOATING_ICON: "wishlist-badge-floating-icon",
|
|
70
74
|
ELEMENT_BADGE_FLOATING_FULL: "wishlist-badge-floating-full",
|
|
@@ -117,14 +121,19 @@ const sanitizeDataId = (id) => {
|
|
|
117
121
|
return getId;
|
|
118
122
|
}
|
|
119
123
|
};
|
|
120
|
-
const detectInitSelector = (element, init) => {
|
|
124
|
+
const detectInitSelector = (element, init, reRender) => {
|
|
121
125
|
let hasRunning = false;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
hasRunning
|
|
126
|
+
if (!reRender) {
|
|
127
|
+
document.body.addEventListener("DOMNodeInserted", () => {
|
|
128
|
+
if (!hasRunning && element) {
|
|
129
|
+
hasRunning = true;
|
|
130
|
+
init();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
if (element)
|
|
125
135
|
init();
|
|
126
|
-
|
|
127
|
-
});
|
|
136
|
+
}
|
|
128
137
|
};
|
|
129
138
|
const isFunction = (data) => typeof data === "function";
|
|
130
139
|
const scrollToElement = (element, headerOffset) => {
|
|
@@ -710,6 +719,29 @@ const BadgeHeaderMenu = (props) => {
|
|
|
710
719
|
!isFirstLoading && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `sledge-wishlist__badge-counter sledge-wishlist__badge-counter-header-menu ${isMaximizeTotalWishlist ? "sledge-wishlist__badge-fit-content" : ""}`, children: isLoading || isRequiredLogin ? 0 : `${isMaximizeTotalWishlist ? "99+" : totalWishlist}` || 0 })
|
|
711
720
|
] });
|
|
712
721
|
};
|
|
722
|
+
const getWishlist = async (query, token) => {
|
|
723
|
+
const { page, limit, sort, keyword, shareId } = query || {};
|
|
724
|
+
let sledgeAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
|
|
725
|
+
let queryParams = "?" + new URLSearchParams({
|
|
726
|
+
page: page || "",
|
|
727
|
+
limit: limit || "",
|
|
728
|
+
sort: sort || "",
|
|
729
|
+
keyword: keyword || "",
|
|
730
|
+
share_id: shareId || ""
|
|
731
|
+
}).toString();
|
|
732
|
+
var myHeaders = new Headers();
|
|
733
|
+
myHeaders.append("Authorization", `Bearer ${sledgeAuthApp}`);
|
|
734
|
+
var requestOptions = {
|
|
735
|
+
method: "GET",
|
|
736
|
+
headers: myHeaders,
|
|
737
|
+
redirect: "follow"
|
|
738
|
+
};
|
|
739
|
+
return await fetch(`${API_URL}/wishlist${queryParams}`, requestOptions).then((response) => response.json()).then((result) => {
|
|
740
|
+
return result;
|
|
741
|
+
}).catch(() => {
|
|
742
|
+
return;
|
|
743
|
+
});
|
|
744
|
+
};
|
|
713
745
|
const addWishlist = async (data) => {
|
|
714
746
|
const { productId, productVariantId, productName, productVendor, productSku, productVariantName, productLink, productImage, productCurrency, productPrice } = data;
|
|
715
747
|
let sledgeAuthApp = localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
|
|
@@ -892,7 +924,7 @@ Badge.Root = BadgeRoot;
|
|
|
892
924
|
Badge.HeaderMenu = BadgeHeaderMenu;
|
|
893
925
|
Badge.FloatingFull = BadgeFloatingFull;
|
|
894
926
|
Badge.FloatingIcon = BadgeFloatingIcon;
|
|
895
|
-
const BadgeInitSelector = () => {
|
|
927
|
+
const BadgeInitSelector = (reRender = false) => {
|
|
896
928
|
const sledgeWishlistSettings = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || "");
|
|
897
929
|
if (!sledgeWishlistSettings)
|
|
898
930
|
return;
|
|
@@ -952,33 +984,41 @@ const BadgeInitSelector = () => {
|
|
|
952
984
|
}
|
|
953
985
|
} else {
|
|
954
986
|
let element = Array.from(document.querySelectorAll(SELECTOR.WISHLIST.ELEMENT_BADGE));
|
|
955
|
-
detectInitSelector(
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
item
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
987
|
+
detectInitSelector(
|
|
988
|
+
element,
|
|
989
|
+
() => {
|
|
990
|
+
if (element.length) {
|
|
991
|
+
element.map((item) => {
|
|
992
|
+
if (item) {
|
|
993
|
+
const USE_PROXY_URL = item.getAttribute(DATASET_ATTRIBUTE_KEY.WISHLIST.USE_PROXY_URL);
|
|
994
|
+
if (item.querySelector(`[${SELECTOR_ATTRIBUTE_KEY}="${INTERNAL_SELECTOR_VALUE.ELEMENT_CONTAINER_WIDGET}"]`))
|
|
995
|
+
item.querySelector(`[${SELECTOR_ATTRIBUTE_KEY}="${INTERNAL_SELECTOR_VALUE.ELEMENT_CONTAINER_WIDGET}"]`).remove();
|
|
996
|
+
let elementContainerWidget = document.createElement("div");
|
|
997
|
+
elementContainerWidget.setAttribute(SELECTOR_ATTRIBUTE_KEY, INTERNAL_SELECTOR_VALUE.ELEMENT_CONTAINER_WIDGET);
|
|
998
|
+
item.appendChild(elementContainerWidget);
|
|
999
|
+
client.createRoot(elementContainerWidget).render(
|
|
1000
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(React__default.StrictMode, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1001
|
+
SledgeContext.Provider,
|
|
1002
|
+
{
|
|
1003
|
+
value: {
|
|
1004
|
+
isRenderApp: {
|
|
1005
|
+
wishlist: true,
|
|
1006
|
+
productReview: true,
|
|
1007
|
+
instantSearch: true
|
|
1008
|
+
},
|
|
1009
|
+
sledgeAnonymId: localStorage.getItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
|
|
1010
|
+
isJsVersion: true
|
|
970
1011
|
},
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
1012
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Badge.Root, { useProxyUrl: Boolean(USE_PROXY_URL && USE_PROXY_URL === "true"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Badge.HeaderMenu, {}) })
|
|
1013
|
+
}
|
|
1014
|
+
) })
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
},
|
|
1020
|
+
reRender
|
|
1021
|
+
);
|
|
982
1022
|
}
|
|
983
1023
|
};
|
|
984
1024
|
const Trigger = (props) => {
|
|
@@ -1038,10 +1078,10 @@ const Trigger = (props) => {
|
|
|
1038
1078
|
const { status, data: response_data } = resAddWishlist || {};
|
|
1039
1079
|
const { code } = status || {};
|
|
1040
1080
|
if (code === 200) {
|
|
1081
|
+
if (((_b2 = (_a2 = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _a2.badge) == null ? void 0 : _b2.trigger) && typeof wishlistChecked !== "boolean")
|
|
1082
|
+
(_f = (_c2 = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _c2.badge) == null ? void 0 : _f.trigger(!((_e = (_d = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _d.badge) == null ? void 0 : _e.value));
|
|
1083
|
+
BadgeInitSelector(true);
|
|
1041
1084
|
if (typeof window !== "undefined") {
|
|
1042
|
-
if (((_b2 = (_a2 = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _a2.badge) == null ? void 0 : _b2.trigger) && typeof wishlistChecked !== "boolean")
|
|
1043
|
-
(_f = (_c2 = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _c2.badge) == null ? void 0 : _f.trigger(!((_e = (_d = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _d.badge) == null ? void 0 : _e.value));
|
|
1044
|
-
BadgeInitSelector();
|
|
1045
1085
|
if (window.sledgeWishlistWidgetListUpdate)
|
|
1046
1086
|
window.sledgeWishlistWidgetListUpdate();
|
|
1047
1087
|
if (window.sledgeWishlistButtonDetailUpdate)
|
|
@@ -1520,23 +1560,39 @@ const getReviewInfo = async (id) => {
|
|
|
1520
1560
|
return;
|
|
1521
1561
|
});
|
|
1522
1562
|
};
|
|
1563
|
+
const getProductsReviewInfo = async (ids, token) => {
|
|
1564
|
+
let convertIds = ids.map((v) => sanitizeDataId(v));
|
|
1565
|
+
let sledgeAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
|
|
1566
|
+
var myHeaders = new Headers();
|
|
1567
|
+
myHeaders.append("Authorization", `Bearer ${sledgeAuthApp}`);
|
|
1568
|
+
var requestOptions = {
|
|
1569
|
+
method: "GET",
|
|
1570
|
+
headers: myHeaders,
|
|
1571
|
+
redirect: "follow"
|
|
1572
|
+
};
|
|
1573
|
+
return await fetch(`${API_URL}/review/info/ids/${convertIds.join(",")}`, requestOptions).then((response) => response.json()).then((result) => {
|
|
1574
|
+
return result;
|
|
1575
|
+
}).catch(() => {
|
|
1576
|
+
return;
|
|
1577
|
+
});
|
|
1578
|
+
};
|
|
1523
1579
|
const Rating = (props) => {
|
|
1524
1580
|
var _a, _b;
|
|
1525
|
-
const {
|
|
1581
|
+
const { total, average, size = "md", params, withSkeletonLoading = true, withTotal = true, isScrollToElementWidget = true, data: propsData, sledgeSettings } = props;
|
|
1526
1582
|
const { productId } = params || {};
|
|
1527
1583
|
const { isRenderApp, triggerRenderMultipleComponent } = React__default.useContext(SledgeContext);
|
|
1528
1584
|
const { productReview: isRenderAppProductReview } = isRenderApp || {};
|
|
1529
|
-
const initLoading = propsData ||
|
|
1585
|
+
const initLoading = propsData || typeof total !== "undefined" || typeof average !== "undefined" ? false : true;
|
|
1530
1586
|
const [isFirstLoading, setIsFirstLoading] = React__default.useState(initLoading);
|
|
1531
1587
|
const [isLoading, setIsLoading] = React__default.useState(initLoading);
|
|
1532
1588
|
const [sizing, setSizing] = React__default.useState(
|
|
1533
|
-
propsData ||
|
|
1589
|
+
propsData || typeof total !== "undefined" || typeof average !== "undefined" ? getSizing(size) : {
|
|
1534
1590
|
width: 0,
|
|
1535
1591
|
height: 0
|
|
1536
1592
|
}
|
|
1537
1593
|
);
|
|
1538
|
-
const [totalReview, setTotalReview] = React__default.useState((propsData == null ? void 0 : propsData.review_count) || 0);
|
|
1539
|
-
const [averageReview, setAverageReview] = React__default.useState(((_a = propsData == null ? void 0 : propsData.rating) == null ? void 0 : _a.average) ||
|
|
1594
|
+
const [totalReview, setTotalReview] = React__default.useState((propsData == null ? void 0 : propsData.review_count) || total || 0);
|
|
1595
|
+
const [averageReview, setAverageReview] = React__default.useState(((_a = propsData == null ? void 0 : propsData.rating) == null ? void 0 : _a.average) || average || "0");
|
|
1540
1596
|
const [dataSettings, setDataSettings] = React__default.useState((sledgeSettings == null ? void 0 : sledgeSettings.review) || {});
|
|
1541
1597
|
const [isFirstTime, setIsFirstTime] = React__default.useState(true);
|
|
1542
1598
|
const previousState = usePrevious({ productId });
|
|
@@ -1575,8 +1631,7 @@ const Rating = (props) => {
|
|
|
1575
1631
|
}
|
|
1576
1632
|
};
|
|
1577
1633
|
const handleRefreshProductRating = async () => {
|
|
1578
|
-
if (
|
|
1579
|
-
setAverageReview(value);
|
|
1634
|
+
if (typeof total !== "undefined" || typeof average !== "undefined") {
|
|
1580
1635
|
setIsLoading(false);
|
|
1581
1636
|
} else {
|
|
1582
1637
|
handleProductRatingInfo(productId);
|
|
@@ -1666,7 +1721,7 @@ const Rating = (props) => {
|
|
|
1666
1721
|
}
|
|
1667
1722
|
return /* @__PURE__ */ createElement("svg", { ...sizing, viewBox: "0 0 30 29", "data-product-review-rating-fill": item <= ratingValue ? "full" : fillOther, key: index }, /* @__PURE__ */ jsxRuntimeExports.jsx("use", { href: "#sledge-product-review-icons-rating-icon" }));
|
|
1668
1723
|
}),
|
|
1669
|
-
|
|
1724
|
+
withTotal ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-product-review__rating-summary-total", children: [
|
|
1670
1725
|
"(",
|
|
1671
1726
|
totalReview,
|
|
1672
1727
|
")"
|
|
@@ -1883,7 +1938,18 @@ const WidgetHeaderSummary = (props) => {
|
|
|
1883
1938
|
{
|
|
1884
1939
|
trigger: /* @__PURE__ */ jsxRuntimeExports.jsxs(motion.div, { initial: false, animate: isOpen ? "open" : "closed", className: "sledge-product-review__widget-summary-trigger", children: [
|
|
1885
1940
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-average", children: averageReview }),
|
|
1886
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-rating", children: !isRefreshRating && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1941
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-rating", children: !isRefreshRating && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1942
|
+
Rating,
|
|
1943
|
+
{
|
|
1944
|
+
data: summaryData,
|
|
1945
|
+
sledgeSettings,
|
|
1946
|
+
average: String(averageReview),
|
|
1947
|
+
size: "md",
|
|
1948
|
+
withSkeletonLoading: false,
|
|
1949
|
+
withTotal: false,
|
|
1950
|
+
isScrollToElementWidget: false
|
|
1951
|
+
}
|
|
1952
|
+
) }),
|
|
1887
1953
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-product-review__widget-summary-total", children: [
|
|
1888
1954
|
totalReview,
|
|
1889
1955
|
" ",
|
|
@@ -1920,7 +1986,18 @@ const WidgetHeaderSummary = (props) => {
|
|
|
1920
1986
|
] }, index);
|
|
1921
1987
|
}) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-dist", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-dist-progress", children: [5, 4, 3, 2, 1].map((item, index) => {
|
|
1922
1988
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-product-review__widget-summary-dist-progress-item", children: [
|
|
1923
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1989
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1990
|
+
Rating,
|
|
1991
|
+
{
|
|
1992
|
+
data: summaryData,
|
|
1993
|
+
sledgeSettings,
|
|
1994
|
+
average: item,
|
|
1995
|
+
size: "sm",
|
|
1996
|
+
withSkeletonLoading: false,
|
|
1997
|
+
withTotal: false,
|
|
1998
|
+
isScrollToElementWidget: false
|
|
1999
|
+
}
|
|
2000
|
+
),
|
|
1924
2001
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1925
2002
|
Progress,
|
|
1926
2003
|
{
|
|
@@ -2136,6 +2213,7 @@ const ProductGrid = ({
|
|
|
2136
2213
|
onAfterRenderProduct && onAfterRenderProduct("success");
|
|
2137
2214
|
}, []);
|
|
2138
2215
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__product-grid ${className}`, "data-grid-type": type, children: data == null ? void 0 : data.map((item, index) => {
|
|
2216
|
+
var _a, _b, _c;
|
|
2139
2217
|
const { product, variants } = item || {};
|
|
2140
2218
|
const { id, title, image, url, vendor = "", currency } = product || {};
|
|
2141
2219
|
const { id: variant_id = "", title: variant_title = "", price = "", sku = "" } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
|
|
@@ -2151,7 +2229,11 @@ const ProductGrid = ({
|
|
|
2151
2229
|
...variant,
|
|
2152
2230
|
is_out_of_stock: Object.hasOwn(variants[index2], "inventory_quantity") ? !inventory_quantity : false
|
|
2153
2231
|
};
|
|
2154
|
-
})
|
|
2232
|
+
}),
|
|
2233
|
+
review: {
|
|
2234
|
+
total: ((_a = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _a.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
|
|
2235
|
+
average: ((_c = (_b = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _b.rating) == null ? void 0 : _c.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
|
|
2236
|
+
}
|
|
2155
2237
|
}
|
|
2156
2238
|
},
|
|
2157
2239
|
showPopupComponent,
|
|
@@ -2678,6 +2760,19 @@ const SearchIconWidget = (props) => {
|
|
|
2678
2760
|
};
|
|
2679
2761
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__icon-widget", onClick: handleShowWidget, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { ...sizing, color: "currentColor" }) });
|
|
2680
2762
|
};
|
|
2763
|
+
const wishlistCheck = async (session, productIds = []) => {
|
|
2764
|
+
let wishlisted = await getWishlist({ limit: 1e3 }, session.token);
|
|
2765
|
+
wishlisted = (wishlisted == null ? void 0 : wishlisted.data) || [];
|
|
2766
|
+
let result = {};
|
|
2767
|
+
for (let id of productIds) {
|
|
2768
|
+
const exist = wishlisted.find((f) => {
|
|
2769
|
+
var _a, _b;
|
|
2770
|
+
return ((_b = (_a = f.product) == null ? void 0 : _a.id) == null ? void 0 : _b.toString()) === id.toString();
|
|
2771
|
+
});
|
|
2772
|
+
result[id] = !!exist;
|
|
2773
|
+
}
|
|
2774
|
+
return result;
|
|
2775
|
+
};
|
|
2681
2776
|
const OtherIndexLists = ({
|
|
2682
2777
|
listsComponent,
|
|
2683
2778
|
name,
|
|
@@ -2742,11 +2837,14 @@ const Global = {
|
|
|
2742
2837
|
};
|
|
2743
2838
|
const SearchIconWidgetPopup = () => {
|
|
2744
2839
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2840
|
+
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
2841
|
+
const { instantSearch: isRenderAppInstantSearch } = isRenderApp || {};
|
|
2745
2842
|
const [isLoading, setIsLoading] = React__default.useState(true);
|
|
2746
2843
|
const [showInfo, setShowInfo] = React__default.useState(false);
|
|
2747
2844
|
const [keyword, setKeyword] = React__default.useState("");
|
|
2748
2845
|
const [searchResultProduct, setSearchResultProduct] = React__default.useState([]);
|
|
2749
2846
|
const [searchResultOther, setSearchResultOther] = React__default.useState([]);
|
|
2847
|
+
const [dataReviews, setDataReviews] = React__default.useState([]);
|
|
2750
2848
|
const [displaySettings, setDisplaySettings] = React__default.useState({});
|
|
2751
2849
|
const [suggestionSettings, setSuggestionSettings] = React__default.useState({});
|
|
2752
2850
|
const [suggestionIndex, setSuggestionIndex] = React__default.useState("");
|
|
@@ -2768,9 +2866,7 @@ const SearchIconWidgetPopup = () => {
|
|
|
2768
2866
|
const searchFieldRef = React__default.useRef(null);
|
|
2769
2867
|
const previousState = usePrevious({ keyword });
|
|
2770
2868
|
const handleMultiSearch = async (data, onSearch = false) => {
|
|
2771
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
|
|
2772
|
-
if (!showInfo)
|
|
2773
|
-
return;
|
|
2869
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
|
|
2774
2870
|
setIsLoading(true);
|
|
2775
2871
|
const { tabs, suffix_index_product, hidden_tags, display, show_out_of_stock } = data;
|
|
2776
2872
|
const suggestion = ((_a2 = display == null ? void 0 : display.search) == null ? void 0 : _a2.suggestion) || {};
|
|
@@ -2818,15 +2914,24 @@ const SearchIconWidgetPopup = () => {
|
|
|
2818
2914
|
let isPriorityZeroCharacter = Boolean(
|
|
2819
2915
|
!keyword.length && Object.keys(suggestion).length && ((_f2 = (_e2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _e2.products) == null ? void 0 : _f2.active) && ((_i2 = (_h2 = (_g2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _g2.products) == null ? void 0 : _h2.list) == null ? void 0 : _i2.length)
|
|
2820
2916
|
);
|
|
2821
|
-
|
|
2917
|
+
let dataSearchResultProduct = isPriorityZeroCharacter ? (_k2 = (_j2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _j2.products) == null ? void 0 : _k2.list : getValueSearchResultProduct;
|
|
2918
|
+
let searchResultProductIds = dataSearchResultProduct.map(({ id }) => id);
|
|
2919
|
+
await wishlistCheck(
|
|
2920
|
+
{
|
|
2921
|
+
token: (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP)) || null
|
|
2922
|
+
},
|
|
2923
|
+
searchResultProductIds
|
|
2924
|
+
);
|
|
2925
|
+
let valueDataReviews = await getProductsReviewInfo(searchResultProductIds);
|
|
2926
|
+
if (((_l2 = valueDataReviews == null ? void 0 : valueDataReviews.status) == null ? void 0 : _l2.code) === 200)
|
|
2927
|
+
setDataReviews(valueDataReviews == null ? void 0 : valueDataReviews.data);
|
|
2928
|
+
setSearchResultProduct(dataSearchResultProduct);
|
|
2822
2929
|
setSearchResultOther(valueSearchResultOther);
|
|
2823
2930
|
setSuggestionIndex(valueSuggestionIndex);
|
|
2824
2931
|
setIsLoading(false);
|
|
2825
2932
|
};
|
|
2826
2933
|
const handleSettings = async (LOCAL_STORAGE_INSTANT_SEARCH_SETTING) => {
|
|
2827
2934
|
var _a2;
|
|
2828
|
-
if (!showInfo)
|
|
2829
|
-
return;
|
|
2830
2935
|
let response;
|
|
2831
2936
|
response = JSON.parse(LOCAL_STORAGE_INSTANT_SEARCH_SETTING);
|
|
2832
2937
|
if (!response)
|
|
@@ -2837,6 +2942,8 @@ const SearchIconWidgetPopup = () => {
|
|
|
2837
2942
|
await handleMultiSearch(response);
|
|
2838
2943
|
};
|
|
2839
2944
|
React__default.useEffect(() => {
|
|
2945
|
+
if (!isRenderAppInstantSearch)
|
|
2946
|
+
return;
|
|
2840
2947
|
if (typeof window !== "undefined") {
|
|
2841
2948
|
window.sledgeInstantSearchIconWidgetPopup = ({
|
|
2842
2949
|
onAfterAddToCart = () => {
|
|
@@ -2878,6 +2985,8 @@ const SearchIconWidgetPopup = () => {
|
|
|
2878
2985
|
};
|
|
2879
2986
|
}
|
|
2880
2987
|
handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "");
|
|
2988
|
+
}, [isRenderAppInstantSearch]);
|
|
2989
|
+
React__default.useEffect(() => {
|
|
2881
2990
|
showInfo ? document.body.classList.add("sledge__open-popup-state") : document.body.classList.remove("sledge__open-popup-state");
|
|
2882
2991
|
}, [showInfo]);
|
|
2883
2992
|
React__default.useEffect(() => {
|
|
@@ -3002,7 +3111,8 @@ const SearchIconWidgetPopup = () => {
|
|
|
3002
3111
|
onAfterRemoveWishlist: handleFunctions.onAfterRemoveWishlist,
|
|
3003
3112
|
onAfterRenderProduct: handleFunctions.onAfterRenderProduct,
|
|
3004
3113
|
showPopupComponent: showInfo,
|
|
3005
|
-
setShowPopupComponent: setShowInfo
|
|
3114
|
+
setShowPopupComponent: setShowInfo,
|
|
3115
|
+
dataReviews
|
|
3006
3116
|
}
|
|
3007
3117
|
) }) : Object.keys(suggestionSettings).length && ((_k = (_j = suggestionSettings[suggestionIndex]) == null ? void 0 : _j.products) == null ? void 0 : _k.active) && ((_n = (_m = (_l = suggestionSettings[suggestionIndex]) == null ? void 0 : _l.products) == null ? void 0 : _m.list) == null ? void 0 : _n.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
3008
3118
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__icon-widget-search-form-result-product-suggestion-no-result-text", children: [
|