@bonlineza/luxity-lib 2.35.5 → 2.35.7

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/build/bundle.js CHANGED
@@ -15769,143 +15769,6 @@
15769
15769
 
15770
15770
  var index$6 = themed(LuxityFooter);
15771
15771
 
15772
- var cssUnit = {
15773
- cm: true,
15774
- mm: true,
15775
- in: true,
15776
- px: true,
15777
- pt: true,
15778
- pc: true,
15779
- em: true,
15780
- ex: true,
15781
- ch: true,
15782
- rem: true,
15783
- vw: true,
15784
- vh: true,
15785
- vmin: true,
15786
- vmax: true,
15787
- "%": true,
15788
- };
15789
- /**
15790
- * If size is a number, append px to the value as default unit.
15791
- * If size is a string, validate against list of valid units.
15792
- * If unit is valid, return size as is.
15793
- * If unit is invalid, console warn issue, replace with px as the unit.
15794
- *
15795
- * @param {(number | string)} size
15796
- * @return {LengthObject} LengthObject
15797
- */
15798
- function parseLengthAndUnit(size) {
15799
- if (typeof size === "number") {
15800
- return {
15801
- value: size,
15802
- unit: "px",
15803
- };
15804
- }
15805
- var value;
15806
- var valueString = (size.match(/^[0-9.]*/) || "").toString();
15807
- if (valueString.includes(".")) {
15808
- value = parseFloat(valueString);
15809
- }
15810
- else {
15811
- value = parseInt(valueString, 10);
15812
- }
15813
- var unit = (size.match(/[^0-9]*$/) || "").toString();
15814
- if (cssUnit[unit]) {
15815
- return {
15816
- value: value,
15817
- unit: unit,
15818
- };
15819
- }
15820
- console.warn("React Spinners: ".concat(size, " is not a valid css value. Defaulting to ").concat(value, "px."));
15821
- return {
15822
- value: value,
15823
- unit: "px",
15824
- };
15825
- }
15826
- /**
15827
- * Take value as an input and return valid css value
15828
- *
15829
- * @param {(number | string)} value
15830
- * @return {string} valid css value
15831
- */
15832
- function cssValue(value) {
15833
- var lengthWithunit = parseLengthAndUnit(value);
15834
- return "".concat(lengthWithunit.value).concat(lengthWithunit.unit);
15835
- }
15836
-
15837
- var createAnimation = function (loaderName, frames, suffix) {
15838
- var animationName = "react-spinners-".concat(loaderName, "-").concat(suffix);
15839
- if (typeof window == "undefined" || !window.document) {
15840
- return animationName;
15841
- }
15842
- var styleEl = document.createElement("style");
15843
- document.head.appendChild(styleEl);
15844
- var styleSheet = styleEl.sheet;
15845
- var keyFrames = "\n @keyframes ".concat(animationName, " {\n ").concat(frames, "\n }\n ");
15846
- if (styleSheet) {
15847
- styleSheet.insertRule(keyFrames, 0);
15848
- }
15849
- return animationName;
15850
- };
15851
-
15852
- var __assign = (undefined && undefined.__assign) || function () {
15853
- __assign = Object.assign || function(t) {
15854
- for (var s, i = 1, n = arguments.length; i < n; i++) {
15855
- s = arguments[i];
15856
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
15857
- t[p] = s[p];
15858
- }
15859
- return t;
15860
- };
15861
- return __assign.apply(this, arguments);
15862
- };
15863
- var __rest = (undefined && undefined.__rest) || function (s, e) {
15864
- var t = {};
15865
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15866
- t[p] = s[p];
15867
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15868
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
15869
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
15870
- t[p[i]] = s[p[i]];
15871
- }
15872
- return t;
15873
- };
15874
- var beat = createAnimation("BeatLoader", "50% {transform: scale(0.75);opacity: 0.2} 100% {transform: scale(1);opacity: 1}", "beat");
15875
- function BeatLoader(_a) {
15876
- var _b = _a.loading, loading = _b === void 0 ? true : _b, _c = _a.color, color = _c === void 0 ? "#000000" : _c, _d = _a.speedMultiplier, speedMultiplier = _d === void 0 ? 1 : _d, _e = _a.cssOverride, cssOverride = _e === void 0 ? {} : _e, _f = _a.size, size = _f === void 0 ? 15 : _f, _g = _a.margin, margin = _g === void 0 ? 2 : _g, additionalprops = __rest(_a, ["loading", "color", "speedMultiplier", "cssOverride", "size", "margin"]);
15877
- var wrapper = __assign({ display: "inherit" }, cssOverride);
15878
- var style = function (i) {
15879
- return {
15880
- display: "inline-block",
15881
- backgroundColor: color,
15882
- width: cssValue(size),
15883
- height: cssValue(size),
15884
- margin: cssValue(margin),
15885
- borderRadius: "100%",
15886
- animation: "".concat(beat, " ").concat(0.7 / speedMultiplier, "s ").concat(i % 2 ? "0s" : "".concat(0.35 / speedMultiplier, "s"), " infinite linear"),
15887
- animationFillMode: "both",
15888
- };
15889
- };
15890
- if (!loading) {
15891
- return null;
15892
- }
15893
- return (React.createElement("span", __assign({ style: wrapper }, additionalprops),
15894
- React.createElement("span", { style: style(1) }),
15895
- React.createElement("span", { style: style(2) }),
15896
- React.createElement("span", { style: style(3) })));
15897
- }
15898
-
15899
- var searchProducts = function searchProducts(search, limit) {
15900
- return {
15901
- query: "\n query SearchProducts($search: String!, $limit: Int!) {\n luxity_products_serach_results(search: $search, limit: $limit) {\n brands {\n name\n link\n }\n products {\n name\n link\n }\n luxity_product_ids\n }\n }\n ",
15902
- variables: {
15903
- search: search,
15904
- limit: limit
15905
- }
15906
- };
15907
- };
15908
-
15909
15772
  var Dropdown$1 = function Dropdown(_ref) {
15910
15773
  var title = _ref.title,
15911
15774
  imageSrc = _ref.imageSrc,
@@ -16098,56 +15961,251 @@
16098
15961
  };
16099
15962
 
16100
15963
  var SearchResults = function SearchResults(_ref) {
15964
+ var _searchResults$brands, _searchResults$produc, _searchResults$brands2, _searchResults$produc2, _initialSearchData$tr, _initialSearchData$la, _limitBrands, _limitBrands2, _initialSearchData$la2, _searchResults$produc3;
15965
+
16101
15966
  var searchValue = _ref.searchValue,
16102
15967
  searchResults = _ref.searchResults,
16103
15968
  onViewAll = _ref.onViewAll,
16104
15969
  searchResultsRef = _ref.searchResultsRef,
16105
15970
  onSearchSubmit = _ref.onSearchSubmit,
16106
- setSearchValue = _ref.setSearchValue;
15971
+ setSearchValue = _ref.setSearchValue,
15972
+ initialSearchData = _ref.initialSearchData,
15973
+ isSearchFocused = _ref.isSearchFocused,
15974
+ setIsSearchFocused = _ref.setIsSearchFocused,
15975
+ currency = _ref.currency,
15976
+ currencySymbol = _ref.currencySymbol;
16107
15977
 
16108
- if (searchValue.trim().length >= 3) {
16109
- if (searchResults.brands.length === 0 && searchResults.products.length === 0) {
16110
- return null;
16111
- }
15978
+ var _useState = React.useState(false),
15979
+ _useState2 = _slicedToArray(_useState, 2),
15980
+ isMobile = _useState2[0],
15981
+ setIsMobile = _useState2[1];
16112
15982
 
16113
- return /*#__PURE__*/React__default.createElement("div", {
16114
- className: "z-50 absolute md:top-14 font-body bg-white w-full lg:w-1/2 flex flex-col md:flex-row md:divide-x divide-black lg:mt-1 shadow-md",
16115
- ref: searchResultsRef
16116
- }, /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
16117
- className: "w-full lg:w-1/3"
16118
- }, /*#__PURE__*/React__default.createElement("p", {
16119
- className: "font-bold p-2 px-4"
16120
- }, "Brands"), searchResults.brands.map(function (brand) {
16121
- return /*#__PURE__*/React__default.createElement("a", {
16122
- key: brand.link,
16123
- href: brand.link,
16124
- className: ""
16125
- }, /*#__PURE__*/React__default.createElement("div", {
16126
- className: "p-2 px-4 hover:bg-gray-100"
16127
- }, brand.name));
15983
+ React.useEffect(function () {
15984
+ var checkIfMobile = function checkIfMobile() {
15985
+ setIsMobile(window.innerWidth <= 1024);
15986
+ };
15987
+
15988
+ checkIfMobile();
15989
+ window.addEventListener('resize', checkIfMobile);
15990
+ return function () {
15991
+ window.removeEventListener('resize', checkIfMobile);
15992
+ };
15993
+ }, []);
15994
+ var shouldShowInitialData = isSearchFocused && (!searchValue || searchValue.trim().length < 3) || (searchValue === null || searchValue === void 0 ? void 0 : searchValue.trim().length) >= 3 && !(searchResults !== null && searchResults !== void 0 && (_searchResults$brands = searchResults.brands) !== null && _searchResults$brands !== void 0 && _searchResults$brands.length) && !(searchResults !== null && searchResults !== void 0 && (_searchResults$produc = searchResults.products) !== null && _searchResults$produc !== void 0 && _searchResults$produc.length);
15995
+ var hasResults = (searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$brands2 = searchResults.brands) === null || _searchResults$brands2 === void 0 ? void 0 : _searchResults$brands2.length) > 0 || (searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$produc2 = searchResults.products) === null || _searchResults$produc2 === void 0 ? void 0 : _searchResults$produc2.length) > 0;
15996
+ var hasInitialData = (initialSearchData === null || initialSearchData === void 0 ? void 0 : (_initialSearchData$tr = initialSearchData.trending_brands) === null || _initialSearchData$tr === void 0 ? void 0 : _initialSearchData$tr.length) > 0 || (initialSearchData === null || initialSearchData === void 0 ? void 0 : (_initialSearchData$la = initialSearchData.latest_products) === null || _initialSearchData$la === void 0 ? void 0 : _initialSearchData$la.length) > 0;
15997
+
15998
+ if (!hasResults && !hasInitialData) {
15999
+ return null;
16000
+ }
16001
+
16002
+ if (!isSearchFocused && !hasResults) {
16003
+ return null;
16004
+ }
16005
+
16006
+ var formatPrice = function formatPrice(price) {
16007
+ var formatter = new Intl.NumberFormat(undefined, {
16008
+ minimumFractionDigits: 0,
16009
+ maximumFractionDigits: 2
16010
+ });
16011
+ return "".concat(currencySymbol).concat(formatter.format(price));
16012
+ };
16013
+
16014
+ var renderProductCard = function renderProductCard(product) {
16015
+ var selectedPrice = product.prices ? product.prices.find(function (p) {
16016
+ return p.currency === currency;
16017
+ }) : {
16018
+ price: product.price,
16019
+ retail_price: product.est_retail_price
16020
+ };
16021
+ return /*#__PURE__*/React__default.createElement("a", {
16022
+ key: product.link,
16023
+ href: product.link,
16024
+ className: "product-card"
16025
+ }, (product.image_url || product.featured_image) && /*#__PURE__*/React__default.createElement("div", {
16026
+ className: "product-card__image-container"
16027
+ }, /*#__PURE__*/React__default.createElement("img", {
16028
+ src: product.featured_image,
16029
+ alt: product.name,
16030
+ className: "product-card__image"
16128
16031
  })), /*#__PURE__*/React__default.createElement("div", {
16129
- className: "w-full lg:w-2/3"
16130
- }, /*#__PURE__*/React__default.createElement("p", {
16131
- className: "font-bold p-2 px-4"
16132
- }, "Products"), searchResults.products.map(function (product) {
16133
- return /*#__PURE__*/React__default.createElement("a", {
16134
- key: product.link,
16135
- href: product.link
16136
- }, /*#__PURE__*/React__default.createElement("div", {
16137
- className: "p-2 px-4 hover:bg-gray-100"
16138
- }, product.name));
16139
- }), /*#__PURE__*/React__default.createElement("button", {
16140
- type: "button",
16141
- onClick: function onClick() {
16142
- onViewAll();
16032
+ className: "product-card__details"
16033
+ }, /*#__PURE__*/React__default.createElement("h3", {
16034
+ className: "product-card__name"
16035
+ }, shouldShowInitialData ? /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement("span", {
16036
+ className: "product-card__brand-name"
16037
+ }, product.brand.toUpperCase()), ' ', product.name) : product.name), /*#__PURE__*/React__default.createElement("div", {
16038
+ className: "product-card__info-row"
16039
+ }, /*#__PURE__*/React__default.createElement("div", {
16040
+ className: "product-card__price-group"
16041
+ }, /*#__PURE__*/React__default.createElement("div", {
16042
+ className: "product-card__price"
16043
+ }, formatPrice(selectedPrice.price)), selectedPrice.retail_price > 1 && /*#__PURE__*/React__default.createElement("div", {
16044
+ className: "product-card__retail-price"
16045
+ }, "Est. Retail: ", formatPrice(selectedPrice.retail_price))), /*#__PURE__*/React__default.createElement("div", {
16046
+ className: "product-card__condition"
16047
+ }, /*#__PURE__*/React__default.createElement("span", {
16048
+ className: "product-card__condition-label"
16049
+ }, "Condition:"), product.condition))));
16050
+ };
16051
+
16052
+ var getBrandLink = function getBrandLink(brand) {
16053
+ return "/products/brands/".concat(brand.slug);
16054
+ };
16055
+
16056
+ var limitBrands = function limitBrands(brands) {
16057
+ if (isMobile && brands && brands.length > 4) {
16058
+ return brands.slice(0, 4);
16059
+ }
16060
+
16061
+ return brands;
16062
+ };
16063
+
16064
+ return /*#__PURE__*/React__default.createElement("div", {
16065
+ className: "search-results",
16066
+ ref: searchResultsRef
16067
+ }, /*#__PURE__*/React__default.createElement("div", {
16068
+ className: "search-results__section"
16069
+ }, /*#__PURE__*/React__default.createElement("h2", {
16070
+ className: "search-results__header"
16071
+ }, shouldShowInitialData ? 'TRENDING SEARCHES' : 'BRANDS'), /*#__PURE__*/React__default.createElement("div", {
16072
+ className: "search-results__list"
16073
+ }, shouldShowInitialData ? (_limitBrands = limitBrands(initialSearchData === null || initialSearchData === void 0 ? void 0 : initialSearchData.trending_brands)) === null || _limitBrands === void 0 ? void 0 : _limitBrands.map(function (brand) {
16074
+ return /*#__PURE__*/React__default.createElement("a", {
16075
+ key: brand.id,
16076
+ href: getBrandLink(brand),
16077
+ className: "search-results__item"
16078
+ }, brand.name);
16079
+ }) : (_limitBrands2 = limitBrands(searchResults === null || searchResults === void 0 ? void 0 : searchResults.brands)) === null || _limitBrands2 === void 0 ? void 0 : _limitBrands2.map(function (brand) {
16080
+ return /*#__PURE__*/React__default.createElement("a", {
16081
+ key: brand.link,
16082
+ href: brand.link,
16083
+ className: "search-results__item"
16084
+ }, brand.name);
16085
+ }))), /*#__PURE__*/React__default.createElement("div", {
16086
+ className: "search-results__section"
16087
+ }, /*#__PURE__*/React__default.createElement("div", {
16088
+ className: "search-results__section-header"
16089
+ }, /*#__PURE__*/React__default.createElement("h2", {
16090
+ className: "search-results__header"
16091
+ }, shouldShowInitialData ? 'POPULAR' : 'TOP MATCHES'), /*#__PURE__*/React__default.createElement("button", {
16092
+ type: "button",
16093
+ className: "search-results__view-all-link",
16094
+ onClick: function onClick() {
16095
+ onViewAll();
16096
+ }
16097
+ }, "View all items")), /*#__PURE__*/React__default.createElement("div", {
16098
+ className: "search-results__product-list"
16099
+ }, shouldShowInitialData ? initialSearchData === null || initialSearchData === void 0 ? void 0 : (_initialSearchData$la2 = initialSearchData.latest_products) === null || _initialSearchData$la2 === void 0 ? void 0 : _initialSearchData$la2.map(renderProductCard) : searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$produc3 = searchResults.products) === null || _searchResults$produc3 === void 0 ? void 0 : _searchResults$produc3.map(renderProductCard)), /*#__PURE__*/React__default.createElement("button", {
16100
+ type: "button",
16101
+ className: "search-results__view-all-button",
16102
+ onClick: function onClick() {
16103
+ onViewAll();
16104
+
16105
+ if (!shouldShowInitialData) {
16143
16106
  onSearchSubmit(searchValue);
16144
16107
  setSearchValue('');
16145
- },
16146
- className: "bottom-0 mt-5 py-3 w-full font-body text-center text-white uppercase bg-black hover:bg-gray-950 border border-black transition-all ease-in-out duration-300 cursor-pointer"
16147
- }, "View all"))));
16148
- }
16108
+ setIsSearchFocused(false);
16109
+ }
16110
+ }
16111
+ }, "View all items")));
16112
+ };
16149
16113
 
16150
- return null;
16114
+ var searchProducts = function searchProducts(search, limit, currencyCode) {
16115
+ return {
16116
+ query: "\n query SearchProducts($search: String!, $limit: Int!, $currencyCode: String!) {\n luxity_products_serach_results(search: $search, limit: $limit, currency_code: $currencyCode) {\n brands {\n name\n link\n }\n products {\n name\n link\n price\n est_retail_price\n condition\n featured_image\n }\n luxity_product_ids\n }\n }\n ",
16117
+ variables: {
16118
+ search: search,
16119
+ limit: limit,
16120
+ currencyCode: currencyCode
16121
+ }
16122
+ };
16123
+ };
16124
+
16125
+ var useSearch = function useSearch(_ref) {
16126
+ var endpoint = _ref.endpoint,
16127
+ onProductIdsReceived = _ref.onProductIdsReceived,
16128
+ currency = _ref.currency;
16129
+ var debounce = React.useCallback(function (func, wait) {
16130
+ var timeout;
16131
+ return function executedFunction() {
16132
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16133
+ args[_key] = arguments[_key];
16134
+ }
16135
+
16136
+ var later = function later() {
16137
+ clearTimeout(timeout);
16138
+ func.apply(void 0, args);
16139
+ };
16140
+
16141
+ clearTimeout(timeout);
16142
+ timeout = setTimeout(later, wait);
16143
+ };
16144
+ }, []);
16145
+ var fetchInitialSearchData = React.useCallback(function (initialSearchDataUrl, setInitialSearchView) {
16146
+ axios.get("".concat(initialSearchDataUrl)).then(function (_ref2) {
16147
+ var data = _ref2.data;
16148
+ setInitialSearchView({
16149
+ trending_brands: data.trending_brands,
16150
+ latest_products: data.latest_products
16151
+ });
16152
+ }).catch(function () {
16153
+ setInitialSearchView({
16154
+ trending_brands: [],
16155
+ latest_products: []
16156
+ });
16157
+ });
16158
+ }, []);
16159
+ var performSearch = React.useCallback(function (nextValue, setSearchResults) {
16160
+ if (!nextValue || nextValue.trim() === '') {
16161
+ setSearchResults({
16162
+ brands: [],
16163
+ products: [],
16164
+ luxity_product_ids: []
16165
+ });
16166
+ return;
16167
+ }
16168
+
16169
+ axios.post(endpoint, searchProducts(nextValue, 3, currency)).then(function (response) {
16170
+ var searchResults = response.data.data.luxity_products_serach_results;
16171
+ setSearchResults(searchResults);
16172
+
16173
+ if (searchResults && searchResults.luxity_product_ids) {
16174
+ onProductIdsReceived(searchResults.luxity_product_ids);
16175
+ }
16176
+ }).catch(function () {
16177
+ setSearchResults({
16178
+ brands: [],
16179
+ products: [],
16180
+ luxity_product_ids: []
16181
+ });
16182
+ });
16183
+ }, [endpoint, currency, onProductIdsReceived]);
16184
+ var debouncedSearch = React.useMemo(function () {
16185
+ return debounce(function (nextValue, setSearchResults) {
16186
+ return performSearch(nextValue, setSearchResults);
16187
+ }, 500);
16188
+ }, [debounce, performSearch]);
16189
+ var createDebouncedSearch = React.useCallback(function (setSearchResults) {
16190
+ return function (nextValue) {
16191
+ return debouncedSearch(nextValue, setSearchResults);
16192
+ };
16193
+ }, [debouncedSearch]);
16194
+ var createImmediateSearch = React.useCallback(function (setSearchValue, setSearchResults, onSearchSubmit) {
16195
+ return function (value) {
16196
+ setSearchValue('');
16197
+ setSearchResults({
16198
+ brands: [],
16199
+ products: []
16200
+ });
16201
+ onSearchSubmit(value);
16202
+ };
16203
+ }, []);
16204
+ return {
16205
+ fetchInitialSearchData: fetchInitialSearchData,
16206
+ createDebouncedSearch: createDebouncedSearch,
16207
+ createImmediateSearch: createImmediateSearch
16208
+ };
16151
16209
  };
16152
16210
 
16153
16211
  var LuxityDesktopHeader = function LuxityDesktopHeader(_ref) {
@@ -16178,9 +16236,11 @@
16178
16236
  onLogoClick = _ref.onLogoClick,
16179
16237
  endpoint = _ref.endpoint,
16180
16238
  menuData = _ref.menuData,
16239
+ initialSearchData = _ref.initialSearchData,
16181
16240
  onSearchSubmit = _ref.onSearchSubmit,
16182
16241
  onProductIdsReceived = _ref.onProductIdsReceived,
16183
16242
  currency = _ref.currency,
16243
+ currencySymbol = _ref.currencySymbol,
16184
16244
  currencyOptions = _ref.currencyOptions,
16185
16245
  onCurrencyChange = _ref.onCurrencyChange,
16186
16246
  isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
@@ -16191,6 +16251,15 @@
16191
16251
  shop = _ref.shop,
16192
16252
  app = _ref.app;
16193
16253
 
16254
+ var _useSearch = useSearch({
16255
+ endpoint: endpoint,
16256
+ onProductIdsReceived: onProductIdsReceived,
16257
+ currency: currency
16258
+ }),
16259
+ fetchInitialSearchData = _useSearch.fetchInitialSearchData,
16260
+ createDebouncedSearch = _useSearch.createDebouncedSearch,
16261
+ createImmediateSearch = _useSearch.createImmediateSearch;
16262
+
16194
16263
  var _useState = React.useState(''),
16195
16264
  _useState2 = _slicedToArray(_useState, 2),
16196
16265
  searchValue = _useState2[0],
@@ -16201,7 +16270,12 @@
16201
16270
  loading = _useState4[0],
16202
16271
  setLoading = _useState4[1];
16203
16272
 
16204
- var _useState5 = React.useState({
16273
+ var _useState5 = React.useState(false),
16274
+ _useState6 = _slicedToArray(_useState5, 2),
16275
+ isSearchFocused = _useState6[0],
16276
+ setIsSearchFocused = _useState6[1];
16277
+
16278
+ var _useState7 = React.useState({
16205
16279
  latestArrivals: [],
16206
16280
  bags: [],
16207
16281
  shoes: [],
@@ -16211,70 +16285,39 @@
16211
16285
  accessoriesCategories: [],
16212
16286
  apparelStyles: []
16213
16287
  }),
16214
- _useState6 = _slicedToArray(_useState5, 2),
16215
- dropdownData = _useState6[0],
16216
- setDropdownData = _useState6[1];
16217
-
16218
- var _useState7 = React.useState(false),
16219
16288
  _useState8 = _slicedToArray(_useState7, 2),
16220
- hasError = _useState8[0],
16221
- setHasError = _useState8[1];
16289
+ dropdownData = _useState8[0],
16290
+ setDropdownData = _useState8[1];
16222
16291
 
16223
- var _useState9 = React.useState(false),
16292
+ var _useState9 = React.useState({
16293
+ trending_brands: [],
16294
+ latest_products: []
16295
+ }),
16224
16296
  _useState10 = _slicedToArray(_useState9, 2),
16225
- searchLoading = _useState10[0],
16226
- setSearchLoading = _useState10[1];
16297
+ initialSearchView = _useState10[0],
16298
+ setInitialSearchView = _useState10[1];
16227
16299
 
16228
- var _useState11 = React.useState({
16300
+ var _useState11 = React.useState(false),
16301
+ _useState12 = _slicedToArray(_useState11, 2),
16302
+ hasError = _useState12[0],
16303
+ setHasError = _useState12[1];
16304
+
16305
+ var _useState13 = React.useState({
16229
16306
  brands: [],
16230
16307
  products: []
16231
16308
  }),
16232
- _useState12 = _slicedToArray(_useState11, 2),
16233
- searchResults = _useState12[0],
16234
- setSearchResults = _useState12[1];
16309
+ _useState14 = _slicedToArray(_useState13, 2),
16310
+ searchResults = _useState14[0],
16311
+ setSearchResults = _useState14[1];
16235
16312
 
16236
16313
  var searchResultsRef = React.useRef(null);
16237
-
16238
- var debounce = function debounce(func, wait) {
16239
- var timeout;
16240
- return function executedFunction() {
16241
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16242
- args[_key] = arguments[_key];
16243
- }
16244
-
16245
- var later = function later() {
16246
- clearTimeout(timeout);
16247
- func.apply(void 0, args);
16248
- };
16249
-
16250
- clearTimeout(timeout);
16251
- timeout = setTimeout(later, wait);
16252
- };
16253
- };
16254
-
16255
- var debouncedSearch = React.useCallback(debounce(function (nextValue) {
16256
- setSearchLoading(true);
16257
- axios.post(endpoint, searchProducts(nextValue, 6)).then(function (response) {
16258
- setSearchResults(response.data.data.luxity_products_serach_results);
16259
- var ids = response.data.data.luxity_products_serach_results.luxity_product_ids;
16260
- onProductIdsReceived(ids);
16261
- setSearchLoading(false);
16262
- }).catch(function () {
16263
- setSearchLoading(false);
16264
- });
16265
- }, 500), [endpoint]);
16266
- var immediateSearch = React.useCallback(function (value) {
16267
- setSearchValue('');
16268
- setSearchResults({
16269
- brands: [],
16270
- products: []
16271
- });
16272
- onSearchSubmit(value);
16273
- }, [onSearchSubmit]);
16314
+ var debouncedSearch = createDebouncedSearch(setSearchResults);
16315
+ var immediateSearch = createImmediateSearch(setSearchValue, setSearchResults, onSearchSubmit);
16274
16316
 
16275
16317
  var handleChange = function handleChange(event) {
16276
16318
  var value = event.target.value;
16277
16319
  setSearchValue(value);
16320
+ setIsSearchFocused(true);
16278
16321
 
16279
16322
  if (value.trim().length >= 3) {
16280
16323
  debouncedSearch(value);
@@ -16290,6 +16333,11 @@
16290
16333
  var handleClickOutside = function handleClickOutside(event) {
16291
16334
  if (searchResultsRef.current && !searchResultsRef.current.contains(event.target)) {
16292
16335
  setSearchValue('');
16336
+ setIsSearchFocused(false);
16337
+ setSearchResults({
16338
+ brands: [],
16339
+ products: []
16340
+ });
16293
16341
  }
16294
16342
  };
16295
16343
 
@@ -16309,6 +16357,8 @@
16309
16357
  } else if (event.key === 'Escape') {
16310
16358
  setSearchValue('');
16311
16359
  }
16360
+
16361
+ setIsSearchFocused(false);
16312
16362
  };
16313
16363
 
16314
16364
  function addCategoryToElements(elements, categoryName) {
@@ -16340,6 +16390,9 @@
16340
16390
  return setHasError(true);
16341
16391
  });
16342
16392
  }, [menuData]);
16393
+ React.useMemo(function () {
16394
+ fetchInitialSearchData(initialSearchData, setInitialSearchView);
16395
+ }, [initialSearchData, fetchInitialSearchData]);
16343
16396
 
16344
16397
  var getMarginRight = function getMarginRight(userIsVip, userName) {
16345
16398
  if (userIsVip) return '15px';
@@ -16359,7 +16412,8 @@
16359
16412
  className: "navbar__logo"
16360
16413
  }, /*#__PURE__*/React__default.createElement("img", {
16361
16414
  src: logoSrc,
16362
- alt: "luxity-logo"
16415
+ alt: "luxity-logo",
16416
+ loading: "eager"
16363
16417
  }))), /*#__PURE__*/React__default.createElement("div", {
16364
16418
  className: "navbar__section"
16365
16419
  }, /*#__PURE__*/React__default.createElement("div", {
@@ -16377,23 +16431,33 @@
16377
16431
  value: searchValue,
16378
16432
  onChange: handleChange,
16379
16433
  onKeyDown: handleKeyDown,
16380
- onClick: onSearch
16381
- }), searchLoading && /*#__PURE__*/React__default.createElement(BeatLoader, {
16382
- color: "#000000",
16383
- loading: searchLoading,
16384
- size: 5,
16385
- "aria-label": "Loading Spinner",
16386
- "data-testid": "loader"
16434
+ onClick: function onClick() {
16435
+ onSearch();
16436
+ setIsSearchFocused(true);
16437
+ },
16438
+ onFocus: function onFocus() {
16439
+ return setIsSearchFocused(true);
16440
+ }
16387
16441
  })), /*#__PURE__*/React__default.createElement(SearchResults, {
16388
16442
  searchValue: searchValue,
16389
16443
  searchResults: searchResults,
16390
16444
  onViewAll: function onViewAll() {
16391
16445
  onSearchSubmit(searchValue);
16392
16446
  setSearchValue('');
16447
+ setSearchResults({
16448
+ brands: [],
16449
+ products: []
16450
+ });
16451
+ setIsSearchFocused(false);
16393
16452
  },
16394
16453
  searchResultsRef: searchResultsRef,
16395
16454
  onSearchSubmit: onSearchSubmit,
16396
- setSearchValue: setSearchValue
16455
+ setSearchValue: setSearchValue,
16456
+ initialSearchData: initialSearchView,
16457
+ isSearchFocused: isSearchFocused,
16458
+ setIsSearchFocused: setIsSearchFocused,
16459
+ currency: currency,
16460
+ currencySymbol: currencySymbol
16397
16461
  }), /*#__PURE__*/React__default.createElement("nav", {
16398
16462
  className: "navbar__nav-links navbar__nav-links--wrap"
16399
16463
  }, /*#__PURE__*/React__default.createElement(DropdownLink$1, {
@@ -17242,6 +17306,7 @@
17242
17306
  onLuxityShopClick = _ref.onLuxityShopClick,
17243
17307
  endpoint = _ref.endpoint,
17244
17308
  menuData = _ref.menuData,
17309
+ initialSearchData = _ref.initialSearchData,
17245
17310
  onSearchSubmit = _ref.onSearchSubmit,
17246
17311
  onProductIdsReceived = _ref.onProductIdsReceived,
17247
17312
  onLogoutClick = _ref.onLogoutClick,
@@ -17255,6 +17320,7 @@
17255
17320
  onPastSalesClick = _ref.onPastSalesClick,
17256
17321
  onPaidOutClick = _ref.onPaidOutClick,
17257
17322
  currency = _ref.currency,
17323
+ currencySymbol = _ref.currencySymbol,
17258
17324
  currencyOptions = _ref.currencyOptions,
17259
17325
  onCurrencyChange = _ref.onCurrencyChange,
17260
17326
  isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
@@ -17263,6 +17329,15 @@
17263
17329
  shop = _ref.shop,
17264
17330
  app = _ref.app;
17265
17331
 
17332
+ var _useSearch = useSearch({
17333
+ endpoint: endpoint,
17334
+ onProductIdsReceived: onProductIdsReceived,
17335
+ currency: currency
17336
+ }),
17337
+ fetchInitialSearchData = _useSearch.fetchInitialSearchData,
17338
+ createDebouncedSearch = _useSearch.createDebouncedSearch,
17339
+ createImmediateSearch = _useSearch.createImmediateSearch;
17340
+
17266
17341
  var _useState = React.useState(''),
17267
17342
  _useState2 = _slicedToArray(_useState, 2),
17268
17343
  searchValue = _useState2[0],
@@ -17278,59 +17353,36 @@
17278
17353
  showSideNav = _useState6[0],
17279
17354
  setShowSideNav = _useState6[1];
17280
17355
 
17281
- var _useState7 = React.useState(false),
17282
- _useState8 = _slicedToArray(_useState7, 2),
17283
- searchLoading = _useState8[0],
17284
- setSearchLoading = _useState8[1];
17285
-
17286
- var _useState9 = React.useState({
17356
+ var _useState7 = React.useState({
17287
17357
  brands: [],
17288
17358
  products: []
17289
17359
  }),
17290
- _useState10 = _slicedToArray(_useState9, 2),
17291
- searchResults = _useState10[0],
17292
- setSearchResults = _useState10[1];
17293
-
17294
- var debounce = function debounce(func, wait) {
17295
- var timeout;
17296
- return function executedFunction() {
17297
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
17298
- args[_key] = arguments[_key];
17299
- }
17360
+ _useState8 = _slicedToArray(_useState7, 2),
17361
+ searchResults = _useState8[0],
17362
+ setSearchResults = _useState8[1];
17300
17363
 
17301
- var later = function later() {
17302
- clearTimeout(timeout);
17303
- func.apply(void 0, args);
17304
- };
17364
+ var _useState9 = React.useState(false),
17365
+ _useState10 = _slicedToArray(_useState9, 2),
17366
+ isSearchFocused = _useState10[0],
17367
+ setIsSearchFocused = _useState10[1];
17305
17368
 
17306
- clearTimeout(timeout);
17307
- timeout = setTimeout(later, wait);
17308
- };
17309
- };
17369
+ var _useState11 = React.useState({
17370
+ trending_brands: [],
17371
+ latest_products: []
17372
+ }),
17373
+ _useState12 = _slicedToArray(_useState11, 2),
17374
+ initialSearchView = _useState12[0],
17375
+ setInitialSearchView = _useState12[1];
17310
17376
 
17311
- var debouncedSearch = React.useCallback(debounce(function (nextValue) {
17312
- setSearchLoading(true);
17313
- axios.post(endpoint, searchProducts(nextValue, 6)).then(function (response) {
17314
- setSearchResults(response.data.data.luxity_products_serach_results);
17315
- var ids = response.data.data.luxity_products_serach_results.luxity_product_ids;
17316
- onProductIdsReceived(ids);
17317
- setSearchLoading(false);
17318
- }).catch(function () {
17319
- setSearchLoading(false);
17320
- });
17321
- }, 500), [endpoint]);
17322
- var immediateSearch = React.useCallback(function (value) {
17323
- setSearchValue('');
17324
- setSearchResults({
17325
- brands: [],
17326
- products: []
17327
- });
17328
- onSearchSubmit(value);
17329
- }, [onSearchSubmit]);
17377
+ var searchResultsRef = React.useRef(null);
17378
+ var searchInputRef = React.useRef(null);
17379
+ var debouncedSearch = createDebouncedSearch(setSearchResults);
17380
+ var immediateSearch = createImmediateSearch(setSearchValue, setSearchResults, onSearchSubmit);
17330
17381
 
17331
17382
  var handleChange = function handleChange(event) {
17332
17383
  var value = event.target.value;
17333
17384
  setSearchValue(value);
17385
+ setIsSearchFocused(true);
17334
17386
 
17335
17387
  if (value.trim().length >= 3) {
17336
17388
  debouncedSearch(value);
@@ -17348,17 +17400,53 @@
17348
17400
 
17349
17401
  if (searchValue.trim().length >= 3) {
17350
17402
  immediateSearch(searchValue);
17403
+ setIsSearchFocused(false);
17351
17404
  }
17352
17405
  } else if (event.key === 'Escape') {
17353
17406
  setSearchValue('');
17407
+ setIsSearchFocused(false);
17354
17408
  }
17355
17409
  };
17356
17410
 
17411
+ React.useMemo(function () {
17412
+ fetchInitialSearchData(initialSearchData, setInitialSearchView);
17413
+ }, [initialSearchData, fetchInitialSearchData]);
17414
+ React.useEffect(function () {
17415
+ var handleClickOutside = function handleClickOutside(event) {
17416
+ if (searchResultsRef.current && !searchResultsRef.current.contains(event.target)) {
17417
+ setSearchValue('');
17418
+ setIsSearchFocused(false);
17419
+ setSearchResults({
17420
+ brands: [],
17421
+ products: []
17422
+ });
17423
+ }
17424
+ };
17425
+
17426
+ document.addEventListener('mousedown', handleClickOutside);
17427
+ return function () {
17428
+ document.removeEventListener('mousedown', handleClickOutside);
17429
+ };
17430
+ }, []);
17431
+ React.useEffect(function () {
17432
+ if (showSearchBar && searchInputRef.current) {
17433
+ searchInputRef.current.focus();
17434
+ }
17435
+ }, [showSearchBar]);
17436
+
17357
17437
  var onSearchClick = function onSearchClick() {
17358
17438
  setShowSearchbar(function (prev) {
17359
17439
  return !prev;
17360
17440
  });
17361
17441
  setSearchValue('');
17442
+ setIsSearchFocused(!showSearchBar);
17443
+
17444
+ if (showSearchBar) {
17445
+ setSearchResults({
17446
+ brands: [],
17447
+ products: []
17448
+ });
17449
+ }
17362
17450
  };
17363
17451
 
17364
17452
  var onMenuClick = function onMenuClick() {
@@ -17464,7 +17552,8 @@
17464
17552
  className: "navbar__logo"
17465
17553
  }, /*#__PURE__*/React__default.createElement("img", {
17466
17554
  src: logoSrc,
17467
- alt: "luxity-logo"
17555
+ alt: "luxity-logo",
17556
+ loading: "eager"
17468
17557
  }))), /*#__PURE__*/React__default.createElement("div", {
17469
17558
  className: "navbar__icons-wrapper"
17470
17559
  }, /*#__PURE__*/React__default.createElement("div", {
@@ -17495,18 +17584,16 @@
17495
17584
  }, /*#__PURE__*/React__default.createElement("div", {
17496
17585
  className: "navbar__product-search"
17497
17586
  }, /*#__PURE__*/React__default.createElement("input", {
17587
+ ref: searchInputRef,
17498
17588
  className: "navbar__form-input",
17499
17589
  type: "text",
17500
17590
  placeholder: "Search for items and designs",
17501
17591
  value: searchValue,
17502
17592
  onChange: handleChange,
17503
- onKeyDown: handleKeyDown
17504
- }), searchLoading && /*#__PURE__*/React__default.createElement(BeatLoader, {
17505
- color: "#000000",
17506
- loading: searchLoading,
17507
- size: 5,
17508
- "aria-label": "Loading Spinner",
17509
- "data-testid": "loader"
17593
+ onKeyDown: handleKeyDown,
17594
+ onFocus: function onFocus() {
17595
+ return setIsSearchFocused(true);
17596
+ }
17510
17597
  })), /*#__PURE__*/React__default.createElement("button", {
17511
17598
  type: "button",
17512
17599
  onClick: onSearchClick
@@ -17516,14 +17603,24 @@
17516
17603
  className: "navbar__input-close-icon"
17517
17604
  })))), /*#__PURE__*/React__default.createElement(SearchResults, {
17518
17605
  searchValue: searchValue,
17519
- searchLoading: searchLoading,
17520
17606
  searchResults: searchResults,
17521
17607
  onViewAll: function onViewAll() {
17522
17608
  onSearchSubmit(searchValue);
17523
17609
  setSearchValue('');
17610
+ setSearchResults({
17611
+ brands: [],
17612
+ products: []
17613
+ });
17614
+ setIsSearchFocused(false);
17524
17615
  },
17525
17616
  onSearchSubmit: onSearchSubmit,
17526
- setSearchValue: setSearchValue
17617
+ setSearchValue: setSearchValue,
17618
+ searchResultsRef: searchResultsRef,
17619
+ initialSearchData: initialSearchView,
17620
+ isSearchFocused: isSearchFocused,
17621
+ setIsSearchFocused: setIsSearchFocused,
17622
+ currency: currency,
17623
+ currencySymbol: currencySymbol
17527
17624
  }), shop && /*#__PURE__*/React__default.createElement(LuxitySideNav, {
17528
17625
  accordionIcon: accordionIcon,
17529
17626
  logoSrc: logoSrc,