@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.
@@ -137,143 +137,6 @@
137
137
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
138
138
  }
139
139
 
140
- var cssUnit = {
141
- cm: true,
142
- mm: true,
143
- in: true,
144
- px: true,
145
- pt: true,
146
- pc: true,
147
- em: true,
148
- ex: true,
149
- ch: true,
150
- rem: true,
151
- vw: true,
152
- vh: true,
153
- vmin: true,
154
- vmax: true,
155
- "%": true,
156
- };
157
- /**
158
- * If size is a number, append px to the value as default unit.
159
- * If size is a string, validate against list of valid units.
160
- * If unit is valid, return size as is.
161
- * If unit is invalid, console warn issue, replace with px as the unit.
162
- *
163
- * @param {(number | string)} size
164
- * @return {LengthObject} LengthObject
165
- */
166
- function parseLengthAndUnit(size) {
167
- if (typeof size === "number") {
168
- return {
169
- value: size,
170
- unit: "px",
171
- };
172
- }
173
- var value;
174
- var valueString = (size.match(/^[0-9.]*/) || "").toString();
175
- if (valueString.includes(".")) {
176
- value = parseFloat(valueString);
177
- }
178
- else {
179
- value = parseInt(valueString, 10);
180
- }
181
- var unit = (size.match(/[^0-9]*$/) || "").toString();
182
- if (cssUnit[unit]) {
183
- return {
184
- value: value,
185
- unit: unit,
186
- };
187
- }
188
- console.warn("React Spinners: ".concat(size, " is not a valid css value. Defaulting to ").concat(value, "px."));
189
- return {
190
- value: value,
191
- unit: "px",
192
- };
193
- }
194
- /**
195
- * Take value as an input and return valid css value
196
- *
197
- * @param {(number | string)} value
198
- * @return {string} valid css value
199
- */
200
- function cssValue(value) {
201
- var lengthWithunit = parseLengthAndUnit(value);
202
- return "".concat(lengthWithunit.value).concat(lengthWithunit.unit);
203
- }
204
-
205
- var createAnimation = function (loaderName, frames, suffix) {
206
- var animationName = "react-spinners-".concat(loaderName, "-").concat(suffix);
207
- if (typeof window == "undefined" || !window.document) {
208
- return animationName;
209
- }
210
- var styleEl = document.createElement("style");
211
- document.head.appendChild(styleEl);
212
- var styleSheet = styleEl.sheet;
213
- var keyFrames = "\n @keyframes ".concat(animationName, " {\n ").concat(frames, "\n }\n ");
214
- if (styleSheet) {
215
- styleSheet.insertRule(keyFrames, 0);
216
- }
217
- return animationName;
218
- };
219
-
220
- var __assign = (undefined && undefined.__assign) || function () {
221
- __assign = Object.assign || function(t) {
222
- for (var s, i = 1, n = arguments.length; i < n; i++) {
223
- s = arguments[i];
224
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
225
- t[p] = s[p];
226
- }
227
- return t;
228
- };
229
- return __assign.apply(this, arguments);
230
- };
231
- var __rest = (undefined && undefined.__rest) || function (s, e) {
232
- var t = {};
233
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
234
- t[p] = s[p];
235
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
236
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
237
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
238
- t[p[i]] = s[p[i]];
239
- }
240
- return t;
241
- };
242
- var beat = createAnimation("BeatLoader", "50% {transform: scale(0.75);opacity: 0.2} 100% {transform: scale(1);opacity: 1}", "beat");
243
- function BeatLoader(_a) {
244
- 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"]);
245
- var wrapper = __assign({ display: "inherit" }, cssOverride);
246
- var style = function (i) {
247
- return {
248
- display: "inline-block",
249
- backgroundColor: color,
250
- width: cssValue(size),
251
- height: cssValue(size),
252
- margin: cssValue(margin),
253
- borderRadius: "100%",
254
- animation: "".concat(beat, " ").concat(0.7 / speedMultiplier, "s ").concat(i % 2 ? "0s" : "".concat(0.35 / speedMultiplier, "s"), " infinite linear"),
255
- animationFillMode: "both",
256
- };
257
- };
258
- if (!loading) {
259
- return null;
260
- }
261
- return (React.createElement("span", __assign({ style: wrapper }, additionalprops),
262
- React.createElement("span", { style: style(1) }),
263
- React.createElement("span", { style: style(2) }),
264
- React.createElement("span", { style: style(3) })));
265
- }
266
-
267
- var searchProducts = function searchProducts(search, limit) {
268
- return {
269
- 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 ",
270
- variables: {
271
- search: search,
272
- limit: limit
273
- }
274
- };
275
- };
276
-
277
140
  var Dropdown = function Dropdown(_ref) {
278
141
  var title = _ref.title,
279
142
  imageSrc = _ref.imageSrc,
@@ -466,56 +329,154 @@
466
329
  };
467
330
 
468
331
  var SearchResults = function SearchResults(_ref) {
332
+ var _searchResults$brands, _searchResults$produc, _searchResults$brands2, _searchResults$produc2, _initialSearchData$tr, _initialSearchData$la, _limitBrands, _limitBrands2, _initialSearchData$la2, _searchResults$produc3;
333
+
469
334
  var searchValue = _ref.searchValue,
470
335
  searchResults = _ref.searchResults,
471
336
  onViewAll = _ref.onViewAll,
472
337
  searchResultsRef = _ref.searchResultsRef,
473
338
  onSearchSubmit = _ref.onSearchSubmit,
474
- setSearchValue = _ref.setSearchValue;
339
+ setSearchValue = _ref.setSearchValue,
340
+ initialSearchData = _ref.initialSearchData,
341
+ isSearchFocused = _ref.isSearchFocused,
342
+ setIsSearchFocused = _ref.setIsSearchFocused,
343
+ currency = _ref.currency,
344
+ currencySymbol = _ref.currencySymbol;
475
345
 
476
- if (searchValue.trim().length >= 3) {
477
- if (searchResults.brands.length === 0 && searchResults.products.length === 0) {
478
- return null;
479
- }
346
+ var _useState = React.useState(false),
347
+ _useState2 = _slicedToArray(_useState, 2),
348
+ isMobile = _useState2[0],
349
+ setIsMobile = _useState2[1];
480
350
 
481
- return /*#__PURE__*/React__default.createElement("div", {
482
- 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",
483
- ref: searchResultsRef
484
- }, /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
485
- className: "w-full lg:w-1/3"
486
- }, /*#__PURE__*/React__default.createElement("p", {
487
- className: "font-bold p-2 px-4"
488
- }, "Brands"), searchResults.brands.map(function (brand) {
489
- return /*#__PURE__*/React__default.createElement("a", {
490
- key: brand.link,
491
- href: brand.link,
492
- className: ""
493
- }, /*#__PURE__*/React__default.createElement("div", {
494
- className: "p-2 px-4 hover:bg-gray-100"
495
- }, brand.name));
351
+ React.useEffect(function () {
352
+ var checkIfMobile = function checkIfMobile() {
353
+ setIsMobile(window.innerWidth <= 1024);
354
+ };
355
+
356
+ checkIfMobile();
357
+ window.addEventListener('resize', checkIfMobile);
358
+ return function () {
359
+ window.removeEventListener('resize', checkIfMobile);
360
+ };
361
+ }, []);
362
+ 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);
363
+ 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;
364
+ 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;
365
+
366
+ if (!hasResults && !hasInitialData) {
367
+ return null;
368
+ }
369
+
370
+ if (!isSearchFocused && !hasResults) {
371
+ return null;
372
+ }
373
+
374
+ var formatPrice = function formatPrice(price) {
375
+ var formatter = new Intl.NumberFormat(undefined, {
376
+ minimumFractionDigits: 0,
377
+ maximumFractionDigits: 2
378
+ });
379
+ return "".concat(currencySymbol).concat(formatter.format(price));
380
+ };
381
+
382
+ var renderProductCard = function renderProductCard(product) {
383
+ var selectedPrice = product.prices ? product.prices.find(function (p) {
384
+ return p.currency === currency;
385
+ }) : {
386
+ price: product.price,
387
+ retail_price: product.est_retail_price
388
+ };
389
+ return /*#__PURE__*/React__default.createElement("a", {
390
+ key: product.link,
391
+ href: product.link,
392
+ className: "product-card"
393
+ }, (product.image_url || product.featured_image) && /*#__PURE__*/React__default.createElement("div", {
394
+ className: "product-card__image-container"
395
+ }, /*#__PURE__*/React__default.createElement("img", {
396
+ src: product.featured_image,
397
+ alt: product.name,
398
+ className: "product-card__image"
496
399
  })), /*#__PURE__*/React__default.createElement("div", {
497
- className: "w-full lg:w-2/3"
498
- }, /*#__PURE__*/React__default.createElement("p", {
499
- className: "font-bold p-2 px-4"
500
- }, "Products"), searchResults.products.map(function (product) {
501
- return /*#__PURE__*/React__default.createElement("a", {
502
- key: product.link,
503
- href: product.link
504
- }, /*#__PURE__*/React__default.createElement("div", {
505
- className: "p-2 px-4 hover:bg-gray-100"
506
- }, product.name));
507
- }), /*#__PURE__*/React__default.createElement("button", {
508
- type: "button",
509
- onClick: function onClick() {
510
- onViewAll();
400
+ className: "product-card__details"
401
+ }, /*#__PURE__*/React__default.createElement("h3", {
402
+ className: "product-card__name"
403
+ }, shouldShowInitialData ? /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement("span", {
404
+ className: "product-card__brand-name"
405
+ }, product.brand.toUpperCase()), ' ', product.name) : product.name), /*#__PURE__*/React__default.createElement("div", {
406
+ className: "product-card__info-row"
407
+ }, /*#__PURE__*/React__default.createElement("div", {
408
+ className: "product-card__price-group"
409
+ }, /*#__PURE__*/React__default.createElement("div", {
410
+ className: "product-card__price"
411
+ }, formatPrice(selectedPrice.price)), selectedPrice.retail_price > 1 && /*#__PURE__*/React__default.createElement("div", {
412
+ className: "product-card__retail-price"
413
+ }, "Est. Retail: ", formatPrice(selectedPrice.retail_price))), /*#__PURE__*/React__default.createElement("div", {
414
+ className: "product-card__condition"
415
+ }, /*#__PURE__*/React__default.createElement("span", {
416
+ className: "product-card__condition-label"
417
+ }, "Condition:"), product.condition))));
418
+ };
419
+
420
+ var getBrandLink = function getBrandLink(brand) {
421
+ return "/products/brands/".concat(brand.slug);
422
+ };
423
+
424
+ var limitBrands = function limitBrands(brands) {
425
+ if (isMobile && brands && brands.length > 4) {
426
+ return brands.slice(0, 4);
427
+ }
428
+
429
+ return brands;
430
+ };
431
+
432
+ return /*#__PURE__*/React__default.createElement("div", {
433
+ className: "search-results",
434
+ ref: searchResultsRef
435
+ }, /*#__PURE__*/React__default.createElement("div", {
436
+ className: "search-results__section"
437
+ }, /*#__PURE__*/React__default.createElement("h2", {
438
+ className: "search-results__header"
439
+ }, shouldShowInitialData ? 'TRENDING SEARCHES' : 'BRANDS'), /*#__PURE__*/React__default.createElement("div", {
440
+ className: "search-results__list"
441
+ }, shouldShowInitialData ? (_limitBrands = limitBrands(initialSearchData === null || initialSearchData === void 0 ? void 0 : initialSearchData.trending_brands)) === null || _limitBrands === void 0 ? void 0 : _limitBrands.map(function (brand) {
442
+ return /*#__PURE__*/React__default.createElement("a", {
443
+ key: brand.id,
444
+ href: getBrandLink(brand),
445
+ className: "search-results__item"
446
+ }, brand.name);
447
+ }) : (_limitBrands2 = limitBrands(searchResults === null || searchResults === void 0 ? void 0 : searchResults.brands)) === null || _limitBrands2 === void 0 ? void 0 : _limitBrands2.map(function (brand) {
448
+ return /*#__PURE__*/React__default.createElement("a", {
449
+ key: brand.link,
450
+ href: brand.link,
451
+ className: "search-results__item"
452
+ }, brand.name);
453
+ }))), /*#__PURE__*/React__default.createElement("div", {
454
+ className: "search-results__section"
455
+ }, /*#__PURE__*/React__default.createElement("div", {
456
+ className: "search-results__section-header"
457
+ }, /*#__PURE__*/React__default.createElement("h2", {
458
+ className: "search-results__header"
459
+ }, shouldShowInitialData ? 'POPULAR' : 'TOP MATCHES'), /*#__PURE__*/React__default.createElement("button", {
460
+ type: "button",
461
+ className: "search-results__view-all-link",
462
+ onClick: function onClick() {
463
+ onViewAll();
464
+ }
465
+ }, "View all items")), /*#__PURE__*/React__default.createElement("div", {
466
+ className: "search-results__product-list"
467
+ }, 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", {
468
+ type: "button",
469
+ className: "search-results__view-all-button",
470
+ onClick: function onClick() {
471
+ onViewAll();
472
+
473
+ if (!shouldShowInitialData) {
511
474
  onSearchSubmit(searchValue);
512
475
  setSearchValue('');
513
- },
514
- 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"
515
- }, "View all"))));
516
- }
517
-
518
- return null;
476
+ setIsSearchFocused(false);
477
+ }
478
+ }
479
+ }, "View all items")));
519
480
  };
520
481
 
521
482
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
@@ -721,6 +682,103 @@
721
682
  }))));
722
683
  };
723
684
 
685
+ var searchProducts = function searchProducts(search, limit, currencyCode) {
686
+ return {
687
+ 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 ",
688
+ variables: {
689
+ search: search,
690
+ limit: limit,
691
+ currencyCode: currencyCode
692
+ }
693
+ };
694
+ };
695
+
696
+ var useSearch = function useSearch(_ref) {
697
+ var endpoint = _ref.endpoint,
698
+ onProductIdsReceived = _ref.onProductIdsReceived,
699
+ currency = _ref.currency;
700
+ var debounce = React.useCallback(function (func, wait) {
701
+ var timeout;
702
+ return function executedFunction() {
703
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
704
+ args[_key] = arguments[_key];
705
+ }
706
+
707
+ var later = function later() {
708
+ clearTimeout(timeout);
709
+ func.apply(void 0, args);
710
+ };
711
+
712
+ clearTimeout(timeout);
713
+ timeout = setTimeout(later, wait);
714
+ };
715
+ }, []);
716
+ var fetchInitialSearchData = React.useCallback(function (initialSearchDataUrl, setInitialSearchView) {
717
+ axios.get("".concat(initialSearchDataUrl)).then(function (_ref2) {
718
+ var data = _ref2.data;
719
+ setInitialSearchView({
720
+ trending_brands: data.trending_brands,
721
+ latest_products: data.latest_products
722
+ });
723
+ }).catch(function () {
724
+ setInitialSearchView({
725
+ trending_brands: [],
726
+ latest_products: []
727
+ });
728
+ });
729
+ }, []);
730
+ var performSearch = React.useCallback(function (nextValue, setSearchResults) {
731
+ if (!nextValue || nextValue.trim() === '') {
732
+ setSearchResults({
733
+ brands: [],
734
+ products: [],
735
+ luxity_product_ids: []
736
+ });
737
+ return;
738
+ }
739
+
740
+ axios.post(endpoint, searchProducts(nextValue, 3, currency)).then(function (response) {
741
+ var searchResults = response.data.data.luxity_products_serach_results;
742
+ setSearchResults(searchResults);
743
+
744
+ if (searchResults && searchResults.luxity_product_ids) {
745
+ onProductIdsReceived(searchResults.luxity_product_ids);
746
+ }
747
+ }).catch(function () {
748
+ setSearchResults({
749
+ brands: [],
750
+ products: [],
751
+ luxity_product_ids: []
752
+ });
753
+ });
754
+ }, [endpoint, currency, onProductIdsReceived]);
755
+ var debouncedSearch = React.useMemo(function () {
756
+ return debounce(function (nextValue, setSearchResults) {
757
+ return performSearch(nextValue, setSearchResults);
758
+ }, 500);
759
+ }, [debounce, performSearch]);
760
+ var createDebouncedSearch = React.useCallback(function (setSearchResults) {
761
+ return function (nextValue) {
762
+ return debouncedSearch(nextValue, setSearchResults);
763
+ };
764
+ }, [debouncedSearch]);
765
+ var createImmediateSearch = React.useCallback(function (setSearchValue, setSearchResults, onSearchSubmit) {
766
+ return function (value) {
767
+ setSearchValue('');
768
+ setSearchResults({
769
+ brands: [],
770
+ products: []
771
+ });
772
+ onSearchSubmit(value);
773
+ };
774
+ }, []);
775
+ return {
776
+ fetchInitialSearchData: fetchInitialSearchData,
777
+ createDebouncedSearch: createDebouncedSearch,
778
+ createImmediateSearch: createImmediateSearch
779
+ };
780
+ };
781
+
724
782
  var LuxityDesktopHeader = function LuxityDesktopHeader(_ref) {
725
783
  var accountIcon = _ref.accountIcon,
726
784
  cartIcon = _ref.cartIcon,
@@ -749,9 +807,11 @@
749
807
  onLogoClick = _ref.onLogoClick,
750
808
  endpoint = _ref.endpoint,
751
809
  menuData = _ref.menuData,
810
+ initialSearchData = _ref.initialSearchData,
752
811
  onSearchSubmit = _ref.onSearchSubmit,
753
812
  onProductIdsReceived = _ref.onProductIdsReceived,
754
813
  currency = _ref.currency,
814
+ currencySymbol = _ref.currencySymbol,
755
815
  currencyOptions = _ref.currencyOptions,
756
816
  onCurrencyChange = _ref.onCurrencyChange,
757
817
  isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
@@ -762,6 +822,15 @@
762
822
  shop = _ref.shop,
763
823
  app = _ref.app;
764
824
 
825
+ var _useSearch = useSearch({
826
+ endpoint: endpoint,
827
+ onProductIdsReceived: onProductIdsReceived,
828
+ currency: currency
829
+ }),
830
+ fetchInitialSearchData = _useSearch.fetchInitialSearchData,
831
+ createDebouncedSearch = _useSearch.createDebouncedSearch,
832
+ createImmediateSearch = _useSearch.createImmediateSearch;
833
+
765
834
  var _useState = React.useState(''),
766
835
  _useState2 = _slicedToArray(_useState, 2),
767
836
  searchValue = _useState2[0],
@@ -772,7 +841,12 @@
772
841
  loading = _useState4[0],
773
842
  setLoading = _useState4[1];
774
843
 
775
- var _useState5 = React.useState({
844
+ var _useState5 = React.useState(false),
845
+ _useState6 = _slicedToArray(_useState5, 2),
846
+ isSearchFocused = _useState6[0],
847
+ setIsSearchFocused = _useState6[1];
848
+
849
+ var _useState7 = React.useState({
776
850
  latestArrivals: [],
777
851
  bags: [],
778
852
  shoes: [],
@@ -782,70 +856,39 @@
782
856
  accessoriesCategories: [],
783
857
  apparelStyles: []
784
858
  }),
785
- _useState6 = _slicedToArray(_useState5, 2),
786
- dropdownData = _useState6[0],
787
- setDropdownData = _useState6[1];
788
-
789
- var _useState7 = React.useState(false),
790
859
  _useState8 = _slicedToArray(_useState7, 2),
791
- hasError = _useState8[0],
792
- setHasError = _useState8[1];
860
+ dropdownData = _useState8[0],
861
+ setDropdownData = _useState8[1];
793
862
 
794
- var _useState9 = React.useState(false),
863
+ var _useState9 = React.useState({
864
+ trending_brands: [],
865
+ latest_products: []
866
+ }),
795
867
  _useState10 = _slicedToArray(_useState9, 2),
796
- searchLoading = _useState10[0],
797
- setSearchLoading = _useState10[1];
868
+ initialSearchView = _useState10[0],
869
+ setInitialSearchView = _useState10[1];
870
+
871
+ var _useState11 = React.useState(false),
872
+ _useState12 = _slicedToArray(_useState11, 2),
873
+ hasError = _useState12[0],
874
+ setHasError = _useState12[1];
798
875
 
799
- var _useState11 = React.useState({
876
+ var _useState13 = React.useState({
800
877
  brands: [],
801
878
  products: []
802
879
  }),
803
- _useState12 = _slicedToArray(_useState11, 2),
804
- searchResults = _useState12[0],
805
- setSearchResults = _useState12[1];
880
+ _useState14 = _slicedToArray(_useState13, 2),
881
+ searchResults = _useState14[0],
882
+ setSearchResults = _useState14[1];
806
883
 
807
884
  var searchResultsRef = React.useRef(null);
808
-
809
- var debounce = function debounce(func, wait) {
810
- var timeout;
811
- return function executedFunction() {
812
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
813
- args[_key] = arguments[_key];
814
- }
815
-
816
- var later = function later() {
817
- clearTimeout(timeout);
818
- func.apply(void 0, args);
819
- };
820
-
821
- clearTimeout(timeout);
822
- timeout = setTimeout(later, wait);
823
- };
824
- };
825
-
826
- var debouncedSearch = React.useCallback(debounce(function (nextValue) {
827
- setSearchLoading(true);
828
- axios.post(endpoint, searchProducts(nextValue, 6)).then(function (response) {
829
- setSearchResults(response.data.data.luxity_products_serach_results);
830
- var ids = response.data.data.luxity_products_serach_results.luxity_product_ids;
831
- onProductIdsReceived(ids);
832
- setSearchLoading(false);
833
- }).catch(function () {
834
- setSearchLoading(false);
835
- });
836
- }, 500), [endpoint]);
837
- var immediateSearch = React.useCallback(function (value) {
838
- setSearchValue('');
839
- setSearchResults({
840
- brands: [],
841
- products: []
842
- });
843
- onSearchSubmit(value);
844
- }, [onSearchSubmit]);
885
+ var debouncedSearch = createDebouncedSearch(setSearchResults);
886
+ var immediateSearch = createImmediateSearch(setSearchValue, setSearchResults, onSearchSubmit);
845
887
 
846
888
  var handleChange = function handleChange(event) {
847
889
  var value = event.target.value;
848
890
  setSearchValue(value);
891
+ setIsSearchFocused(true);
849
892
 
850
893
  if (value.trim().length >= 3) {
851
894
  debouncedSearch(value);
@@ -861,6 +904,11 @@
861
904
  var handleClickOutside = function handleClickOutside(event) {
862
905
  if (searchResultsRef.current && !searchResultsRef.current.contains(event.target)) {
863
906
  setSearchValue('');
907
+ setIsSearchFocused(false);
908
+ setSearchResults({
909
+ brands: [],
910
+ products: []
911
+ });
864
912
  }
865
913
  };
866
914
 
@@ -880,6 +928,8 @@
880
928
  } else if (event.key === 'Escape') {
881
929
  setSearchValue('');
882
930
  }
931
+
932
+ setIsSearchFocused(false);
883
933
  };
884
934
 
885
935
  function addCategoryToElements(elements, categoryName) {
@@ -911,6 +961,9 @@
911
961
  return setHasError(true);
912
962
  });
913
963
  }, [menuData]);
964
+ React.useMemo(function () {
965
+ fetchInitialSearchData(initialSearchData, setInitialSearchView);
966
+ }, [initialSearchData, fetchInitialSearchData]);
914
967
 
915
968
  var getMarginRight = function getMarginRight(userIsVip, userName) {
916
969
  if (userIsVip) return '15px';
@@ -930,7 +983,8 @@
930
983
  className: "navbar__logo"
931
984
  }, /*#__PURE__*/React__default.createElement("img", {
932
985
  src: logoSrc,
933
- alt: "luxity-logo"
986
+ alt: "luxity-logo",
987
+ loading: "eager"
934
988
  }))), /*#__PURE__*/React__default.createElement("div", {
935
989
  className: "navbar__section"
936
990
  }, /*#__PURE__*/React__default.createElement("div", {
@@ -948,23 +1002,33 @@
948
1002
  value: searchValue,
949
1003
  onChange: handleChange,
950
1004
  onKeyDown: handleKeyDown,
951
- onClick: onSearch
952
- }), searchLoading && /*#__PURE__*/React__default.createElement(BeatLoader, {
953
- color: "#000000",
954
- loading: searchLoading,
955
- size: 5,
956
- "aria-label": "Loading Spinner",
957
- "data-testid": "loader"
1005
+ onClick: function onClick() {
1006
+ onSearch();
1007
+ setIsSearchFocused(true);
1008
+ },
1009
+ onFocus: function onFocus() {
1010
+ return setIsSearchFocused(true);
1011
+ }
958
1012
  })), /*#__PURE__*/React__default.createElement(SearchResults, {
959
1013
  searchValue: searchValue,
960
1014
  searchResults: searchResults,
961
1015
  onViewAll: function onViewAll() {
962
1016
  onSearchSubmit(searchValue);
963
1017
  setSearchValue('');
1018
+ setSearchResults({
1019
+ brands: [],
1020
+ products: []
1021
+ });
1022
+ setIsSearchFocused(false);
964
1023
  },
965
1024
  searchResultsRef: searchResultsRef,
966
1025
  onSearchSubmit: onSearchSubmit,
967
- setSearchValue: setSearchValue
1026
+ setSearchValue: setSearchValue,
1027
+ initialSearchData: initialSearchView,
1028
+ isSearchFocused: isSearchFocused,
1029
+ setIsSearchFocused: setIsSearchFocused,
1030
+ currency: currency,
1031
+ currencySymbol: currencySymbol
968
1032
  }), /*#__PURE__*/React__default.createElement("nav", {
969
1033
  className: "navbar__nav-links navbar__nav-links--wrap"
970
1034
  }, /*#__PURE__*/React__default.createElement(DropdownLink, {