@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,133 +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
140
  var LuxityAppSideNav = function LuxityAppSideNav(_ref) {
268
141
  var closeIcon = _ref.closeIcon,
269
142
  accountIcon = _ref.accountIcon,
@@ -1166,67 +1039,252 @@
1166
1039
  })));
1167
1040
  };
1168
1041
 
1169
- var searchProducts = function searchProducts(search, limit) {
1170
- return {
1171
- 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 ",
1172
- variables: {
1173
- search: search,
1174
- limit: limit
1175
- }
1176
- };
1177
- };
1178
-
1179
1042
  var SearchResults = function SearchResults(_ref) {
1043
+ var _searchResults$brands, _searchResults$produc, _searchResults$brands2, _searchResults$produc2, _initialSearchData$tr, _initialSearchData$la, _limitBrands, _limitBrands2, _initialSearchData$la2, _searchResults$produc3;
1044
+
1180
1045
  var searchValue = _ref.searchValue,
1181
1046
  searchResults = _ref.searchResults,
1182
1047
  onViewAll = _ref.onViewAll,
1183
1048
  searchResultsRef = _ref.searchResultsRef,
1184
1049
  onSearchSubmit = _ref.onSearchSubmit,
1185
- setSearchValue = _ref.setSearchValue;
1050
+ setSearchValue = _ref.setSearchValue,
1051
+ initialSearchData = _ref.initialSearchData,
1052
+ isSearchFocused = _ref.isSearchFocused,
1053
+ setIsSearchFocused = _ref.setIsSearchFocused,
1054
+ currency = _ref.currency,
1055
+ currencySymbol = _ref.currencySymbol;
1186
1056
 
1187
- if (searchValue.trim().length >= 3) {
1188
- if (searchResults.brands.length === 0 && searchResults.products.length === 0) {
1189
- return null;
1190
- }
1057
+ var _useState = React.useState(false),
1058
+ _useState2 = _slicedToArray(_useState, 2),
1059
+ isMobile = _useState2[0],
1060
+ setIsMobile = _useState2[1];
1061
+
1062
+ React.useEffect(function () {
1063
+ var checkIfMobile = function checkIfMobile() {
1064
+ setIsMobile(window.innerWidth <= 1024);
1065
+ };
1066
+
1067
+ checkIfMobile();
1068
+ window.addEventListener('resize', checkIfMobile);
1069
+ return function () {
1070
+ window.removeEventListener('resize', checkIfMobile);
1071
+ };
1072
+ }, []);
1073
+ 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);
1074
+ 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;
1075
+ 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;
1076
+
1077
+ if (!hasResults && !hasInitialData) {
1078
+ return null;
1079
+ }
1080
+
1081
+ if (!isSearchFocused && !hasResults) {
1082
+ return null;
1083
+ }
1084
+
1085
+ var formatPrice = function formatPrice(price) {
1086
+ var formatter = new Intl.NumberFormat(undefined, {
1087
+ minimumFractionDigits: 0,
1088
+ maximumFractionDigits: 2
1089
+ });
1090
+ return "".concat(currencySymbol).concat(formatter.format(price));
1091
+ };
1191
1092
 
1192
- return /*#__PURE__*/React__default.createElement("div", {
1193
- 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",
1194
- ref: searchResultsRef
1195
- }, /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
1196
- className: "w-full lg:w-1/3"
1197
- }, /*#__PURE__*/React__default.createElement("p", {
1198
- className: "font-bold p-2 px-4"
1199
- }, "Brands"), searchResults.brands.map(function (brand) {
1200
- return /*#__PURE__*/React__default.createElement("a", {
1201
- key: brand.link,
1202
- href: brand.link,
1203
- className: ""
1204
- }, /*#__PURE__*/React__default.createElement("div", {
1205
- className: "p-2 px-4 hover:bg-gray-100"
1206
- }, brand.name));
1093
+ var renderProductCard = function renderProductCard(product) {
1094
+ var selectedPrice = product.prices ? product.prices.find(function (p) {
1095
+ return p.currency === currency;
1096
+ }) : {
1097
+ price: product.price,
1098
+ retail_price: product.est_retail_price
1099
+ };
1100
+ return /*#__PURE__*/React__default.createElement("a", {
1101
+ key: product.link,
1102
+ href: product.link,
1103
+ className: "product-card"
1104
+ }, (product.image_url || product.featured_image) && /*#__PURE__*/React__default.createElement("div", {
1105
+ className: "product-card__image-container"
1106
+ }, /*#__PURE__*/React__default.createElement("img", {
1107
+ src: product.featured_image,
1108
+ alt: product.name,
1109
+ className: "product-card__image"
1207
1110
  })), /*#__PURE__*/React__default.createElement("div", {
1208
- className: "w-full lg:w-2/3"
1209
- }, /*#__PURE__*/React__default.createElement("p", {
1210
- className: "font-bold p-2 px-4"
1211
- }, "Products"), searchResults.products.map(function (product) {
1212
- return /*#__PURE__*/React__default.createElement("a", {
1213
- key: product.link,
1214
- href: product.link
1215
- }, /*#__PURE__*/React__default.createElement("div", {
1216
- className: "p-2 px-4 hover:bg-gray-100"
1217
- }, product.name));
1218
- }), /*#__PURE__*/React__default.createElement("button", {
1219
- type: "button",
1220
- onClick: function onClick() {
1221
- onViewAll();
1111
+ className: "product-card__details"
1112
+ }, /*#__PURE__*/React__default.createElement("h3", {
1113
+ className: "product-card__name"
1114
+ }, shouldShowInitialData ? /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement("span", {
1115
+ className: "product-card__brand-name"
1116
+ }, product.brand.toUpperCase()), ' ', product.name) : product.name), /*#__PURE__*/React__default.createElement("div", {
1117
+ className: "product-card__info-row"
1118
+ }, /*#__PURE__*/React__default.createElement("div", {
1119
+ className: "product-card__price-group"
1120
+ }, /*#__PURE__*/React__default.createElement("div", {
1121
+ className: "product-card__price"
1122
+ }, formatPrice(selectedPrice.price)), selectedPrice.retail_price > 1 && /*#__PURE__*/React__default.createElement("div", {
1123
+ className: "product-card__retail-price"
1124
+ }, "Est. Retail: ", formatPrice(selectedPrice.retail_price))), /*#__PURE__*/React__default.createElement("div", {
1125
+ className: "product-card__condition"
1126
+ }, /*#__PURE__*/React__default.createElement("span", {
1127
+ className: "product-card__condition-label"
1128
+ }, "Condition:"), product.condition))));
1129
+ };
1130
+
1131
+ var getBrandLink = function getBrandLink(brand) {
1132
+ return "/products/brands/".concat(brand.slug);
1133
+ };
1134
+
1135
+ var limitBrands = function limitBrands(brands) {
1136
+ if (isMobile && brands && brands.length > 4) {
1137
+ return brands.slice(0, 4);
1138
+ }
1139
+
1140
+ return brands;
1141
+ };
1142
+
1143
+ return /*#__PURE__*/React__default.createElement("div", {
1144
+ className: "search-results",
1145
+ ref: searchResultsRef
1146
+ }, /*#__PURE__*/React__default.createElement("div", {
1147
+ className: "search-results__section"
1148
+ }, /*#__PURE__*/React__default.createElement("h2", {
1149
+ className: "search-results__header"
1150
+ }, shouldShowInitialData ? 'TRENDING SEARCHES' : 'BRANDS'), /*#__PURE__*/React__default.createElement("div", {
1151
+ className: "search-results__list"
1152
+ }, shouldShowInitialData ? (_limitBrands = limitBrands(initialSearchData === null || initialSearchData === void 0 ? void 0 : initialSearchData.trending_brands)) === null || _limitBrands === void 0 ? void 0 : _limitBrands.map(function (brand) {
1153
+ return /*#__PURE__*/React__default.createElement("a", {
1154
+ key: brand.id,
1155
+ href: getBrandLink(brand),
1156
+ className: "search-results__item"
1157
+ }, brand.name);
1158
+ }) : (_limitBrands2 = limitBrands(searchResults === null || searchResults === void 0 ? void 0 : searchResults.brands)) === null || _limitBrands2 === void 0 ? void 0 : _limitBrands2.map(function (brand) {
1159
+ return /*#__PURE__*/React__default.createElement("a", {
1160
+ key: brand.link,
1161
+ href: brand.link,
1162
+ className: "search-results__item"
1163
+ }, brand.name);
1164
+ }))), /*#__PURE__*/React__default.createElement("div", {
1165
+ className: "search-results__section"
1166
+ }, /*#__PURE__*/React__default.createElement("div", {
1167
+ className: "search-results__section-header"
1168
+ }, /*#__PURE__*/React__default.createElement("h2", {
1169
+ className: "search-results__header"
1170
+ }, shouldShowInitialData ? 'POPULAR' : 'TOP MATCHES'), /*#__PURE__*/React__default.createElement("button", {
1171
+ type: "button",
1172
+ className: "search-results__view-all-link",
1173
+ onClick: function onClick() {
1174
+ onViewAll();
1175
+ }
1176
+ }, "View all items")), /*#__PURE__*/React__default.createElement("div", {
1177
+ className: "search-results__product-list"
1178
+ }, 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", {
1179
+ type: "button",
1180
+ className: "search-results__view-all-button",
1181
+ onClick: function onClick() {
1182
+ onViewAll();
1183
+
1184
+ if (!shouldShowInitialData) {
1222
1185
  onSearchSubmit(searchValue);
1223
1186
  setSearchValue('');
1224
- },
1225
- 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"
1226
- }, "View all"))));
1227
- }
1187
+ setIsSearchFocused(false);
1188
+ }
1189
+ }
1190
+ }, "View all items")));
1191
+ };
1192
+
1193
+ var searchProducts = function searchProducts(search, limit, currencyCode) {
1194
+ return {
1195
+ 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 ",
1196
+ variables: {
1197
+ search: search,
1198
+ limit: limit,
1199
+ currencyCode: currencyCode
1200
+ }
1201
+ };
1202
+ };
1203
+
1204
+ var useSearch = function useSearch(_ref) {
1205
+ var endpoint = _ref.endpoint,
1206
+ onProductIdsReceived = _ref.onProductIdsReceived,
1207
+ currency = _ref.currency;
1208
+ var debounce = React.useCallback(function (func, wait) {
1209
+ var timeout;
1210
+ return function executedFunction() {
1211
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1212
+ args[_key] = arguments[_key];
1213
+ }
1214
+
1215
+ var later = function later() {
1216
+ clearTimeout(timeout);
1217
+ func.apply(void 0, args);
1218
+ };
1219
+
1220
+ clearTimeout(timeout);
1221
+ timeout = setTimeout(later, wait);
1222
+ };
1223
+ }, []);
1224
+ var fetchInitialSearchData = React.useCallback(function (initialSearchDataUrl, setInitialSearchView) {
1225
+ axios.get("".concat(initialSearchDataUrl)).then(function (_ref2) {
1226
+ var data = _ref2.data;
1227
+ setInitialSearchView({
1228
+ trending_brands: data.trending_brands,
1229
+ latest_products: data.latest_products
1230
+ });
1231
+ }).catch(function () {
1232
+ setInitialSearchView({
1233
+ trending_brands: [],
1234
+ latest_products: []
1235
+ });
1236
+ });
1237
+ }, []);
1238
+ var performSearch = React.useCallback(function (nextValue, setSearchResults) {
1239
+ if (!nextValue || nextValue.trim() === '') {
1240
+ setSearchResults({
1241
+ brands: [],
1242
+ products: [],
1243
+ luxity_product_ids: []
1244
+ });
1245
+ return;
1246
+ }
1228
1247
 
1229
- return null;
1248
+ axios.post(endpoint, searchProducts(nextValue, 3, currency)).then(function (response) {
1249
+ var searchResults = response.data.data.luxity_products_serach_results;
1250
+ setSearchResults(searchResults);
1251
+
1252
+ if (searchResults && searchResults.luxity_product_ids) {
1253
+ onProductIdsReceived(searchResults.luxity_product_ids);
1254
+ }
1255
+ }).catch(function () {
1256
+ setSearchResults({
1257
+ brands: [],
1258
+ products: [],
1259
+ luxity_product_ids: []
1260
+ });
1261
+ });
1262
+ }, [endpoint, currency, onProductIdsReceived]);
1263
+ var debouncedSearch = React.useMemo(function () {
1264
+ return debounce(function (nextValue, setSearchResults) {
1265
+ return performSearch(nextValue, setSearchResults);
1266
+ }, 500);
1267
+ }, [debounce, performSearch]);
1268
+ var createDebouncedSearch = React.useCallback(function (setSearchResults) {
1269
+ return function (nextValue) {
1270
+ return debouncedSearch(nextValue, setSearchResults);
1271
+ };
1272
+ }, [debouncedSearch]);
1273
+ var createImmediateSearch = React.useCallback(function (setSearchValue, setSearchResults, onSearchSubmit) {
1274
+ return function (value) {
1275
+ setSearchValue('');
1276
+ setSearchResults({
1277
+ brands: [],
1278
+ products: []
1279
+ });
1280
+ onSearchSubmit(value);
1281
+ };
1282
+ }, []);
1283
+ return {
1284
+ fetchInitialSearchData: fetchInitialSearchData,
1285
+ createDebouncedSearch: createDebouncedSearch,
1286
+ createImmediateSearch: createImmediateSearch
1287
+ };
1230
1288
  };
1231
1289
 
1232
1290
  var LuxityMobileHeader = function LuxityMobileHeader(_ref) {
@@ -1256,6 +1314,7 @@
1256
1314
  onLuxityShopClick = _ref.onLuxityShopClick,
1257
1315
  endpoint = _ref.endpoint,
1258
1316
  menuData = _ref.menuData,
1317
+ initialSearchData = _ref.initialSearchData,
1259
1318
  onSearchSubmit = _ref.onSearchSubmit,
1260
1319
  onProductIdsReceived = _ref.onProductIdsReceived,
1261
1320
  onLogoutClick = _ref.onLogoutClick,
@@ -1269,6 +1328,7 @@
1269
1328
  onPastSalesClick = _ref.onPastSalesClick,
1270
1329
  onPaidOutClick = _ref.onPaidOutClick,
1271
1330
  currency = _ref.currency,
1331
+ currencySymbol = _ref.currencySymbol,
1272
1332
  currencyOptions = _ref.currencyOptions,
1273
1333
  onCurrencyChange = _ref.onCurrencyChange,
1274
1334
  isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
@@ -1277,6 +1337,15 @@
1277
1337
  shop = _ref.shop,
1278
1338
  app = _ref.app;
1279
1339
 
1340
+ var _useSearch = useSearch({
1341
+ endpoint: endpoint,
1342
+ onProductIdsReceived: onProductIdsReceived,
1343
+ currency: currency
1344
+ }),
1345
+ fetchInitialSearchData = _useSearch.fetchInitialSearchData,
1346
+ createDebouncedSearch = _useSearch.createDebouncedSearch,
1347
+ createImmediateSearch = _useSearch.createImmediateSearch;
1348
+
1280
1349
  var _useState = React.useState(''),
1281
1350
  _useState2 = _slicedToArray(_useState, 2),
1282
1351
  searchValue = _useState2[0],
@@ -1292,59 +1361,36 @@
1292
1361
  showSideNav = _useState6[0],
1293
1362
  setShowSideNav = _useState6[1];
1294
1363
 
1295
- var _useState7 = React.useState(false),
1296
- _useState8 = _slicedToArray(_useState7, 2),
1297
- searchLoading = _useState8[0],
1298
- setSearchLoading = _useState8[1];
1299
-
1300
- var _useState9 = React.useState({
1364
+ var _useState7 = React.useState({
1301
1365
  brands: [],
1302
1366
  products: []
1303
1367
  }),
1304
- _useState10 = _slicedToArray(_useState9, 2),
1305
- searchResults = _useState10[0],
1306
- setSearchResults = _useState10[1];
1307
-
1308
- var debounce = function debounce(func, wait) {
1309
- var timeout;
1310
- return function executedFunction() {
1311
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1312
- args[_key] = arguments[_key];
1313
- }
1368
+ _useState8 = _slicedToArray(_useState7, 2),
1369
+ searchResults = _useState8[0],
1370
+ setSearchResults = _useState8[1];
1314
1371
 
1315
- var later = function later() {
1316
- clearTimeout(timeout);
1317
- func.apply(void 0, args);
1318
- };
1372
+ var _useState9 = React.useState(false),
1373
+ _useState10 = _slicedToArray(_useState9, 2),
1374
+ isSearchFocused = _useState10[0],
1375
+ setIsSearchFocused = _useState10[1];
1319
1376
 
1320
- clearTimeout(timeout);
1321
- timeout = setTimeout(later, wait);
1322
- };
1323
- };
1377
+ var _useState11 = React.useState({
1378
+ trending_brands: [],
1379
+ latest_products: []
1380
+ }),
1381
+ _useState12 = _slicedToArray(_useState11, 2),
1382
+ initialSearchView = _useState12[0],
1383
+ setInitialSearchView = _useState12[1];
1324
1384
 
1325
- var debouncedSearch = React.useCallback(debounce(function (nextValue) {
1326
- setSearchLoading(true);
1327
- axios.post(endpoint, searchProducts(nextValue, 6)).then(function (response) {
1328
- setSearchResults(response.data.data.luxity_products_serach_results);
1329
- var ids = response.data.data.luxity_products_serach_results.luxity_product_ids;
1330
- onProductIdsReceived(ids);
1331
- setSearchLoading(false);
1332
- }).catch(function () {
1333
- setSearchLoading(false);
1334
- });
1335
- }, 500), [endpoint]);
1336
- var immediateSearch = React.useCallback(function (value) {
1337
- setSearchValue('');
1338
- setSearchResults({
1339
- brands: [],
1340
- products: []
1341
- });
1342
- onSearchSubmit(value);
1343
- }, [onSearchSubmit]);
1385
+ var searchResultsRef = React.useRef(null);
1386
+ var searchInputRef = React.useRef(null);
1387
+ var debouncedSearch = createDebouncedSearch(setSearchResults);
1388
+ var immediateSearch = createImmediateSearch(setSearchValue, setSearchResults, onSearchSubmit);
1344
1389
 
1345
1390
  var handleChange = function handleChange(event) {
1346
1391
  var value = event.target.value;
1347
1392
  setSearchValue(value);
1393
+ setIsSearchFocused(true);
1348
1394
 
1349
1395
  if (value.trim().length >= 3) {
1350
1396
  debouncedSearch(value);
@@ -1362,17 +1408,53 @@
1362
1408
 
1363
1409
  if (searchValue.trim().length >= 3) {
1364
1410
  immediateSearch(searchValue);
1411
+ setIsSearchFocused(false);
1365
1412
  }
1366
1413
  } else if (event.key === 'Escape') {
1367
1414
  setSearchValue('');
1415
+ setIsSearchFocused(false);
1368
1416
  }
1369
1417
  };
1370
1418
 
1419
+ React.useMemo(function () {
1420
+ fetchInitialSearchData(initialSearchData, setInitialSearchView);
1421
+ }, [initialSearchData, fetchInitialSearchData]);
1422
+ React.useEffect(function () {
1423
+ var handleClickOutside = function handleClickOutside(event) {
1424
+ if (searchResultsRef.current && !searchResultsRef.current.contains(event.target)) {
1425
+ setSearchValue('');
1426
+ setIsSearchFocused(false);
1427
+ setSearchResults({
1428
+ brands: [],
1429
+ products: []
1430
+ });
1431
+ }
1432
+ };
1433
+
1434
+ document.addEventListener('mousedown', handleClickOutside);
1435
+ return function () {
1436
+ document.removeEventListener('mousedown', handleClickOutside);
1437
+ };
1438
+ }, []);
1439
+ React.useEffect(function () {
1440
+ if (showSearchBar && searchInputRef.current) {
1441
+ searchInputRef.current.focus();
1442
+ }
1443
+ }, [showSearchBar]);
1444
+
1371
1445
  var onSearchClick = function onSearchClick() {
1372
1446
  setShowSearchbar(function (prev) {
1373
1447
  return !prev;
1374
1448
  });
1375
1449
  setSearchValue('');
1450
+ setIsSearchFocused(!showSearchBar);
1451
+
1452
+ if (showSearchBar) {
1453
+ setSearchResults({
1454
+ brands: [],
1455
+ products: []
1456
+ });
1457
+ }
1376
1458
  };
1377
1459
 
1378
1460
  var onMenuClick = function onMenuClick() {
@@ -1478,7 +1560,8 @@
1478
1560
  className: "navbar__logo"
1479
1561
  }, /*#__PURE__*/React__default.createElement("img", {
1480
1562
  src: logoSrc,
1481
- alt: "luxity-logo"
1563
+ alt: "luxity-logo",
1564
+ loading: "eager"
1482
1565
  }))), /*#__PURE__*/React__default.createElement("div", {
1483
1566
  className: "navbar__icons-wrapper"
1484
1567
  }, /*#__PURE__*/React__default.createElement("div", {
@@ -1509,18 +1592,16 @@
1509
1592
  }, /*#__PURE__*/React__default.createElement("div", {
1510
1593
  className: "navbar__product-search"
1511
1594
  }, /*#__PURE__*/React__default.createElement("input", {
1595
+ ref: searchInputRef,
1512
1596
  className: "navbar__form-input",
1513
1597
  type: "text",
1514
1598
  placeholder: "Search for items and designs",
1515
1599
  value: searchValue,
1516
1600
  onChange: handleChange,
1517
- onKeyDown: handleKeyDown
1518
- }), searchLoading && /*#__PURE__*/React__default.createElement(BeatLoader, {
1519
- color: "#000000",
1520
- loading: searchLoading,
1521
- size: 5,
1522
- "aria-label": "Loading Spinner",
1523
- "data-testid": "loader"
1601
+ onKeyDown: handleKeyDown,
1602
+ onFocus: function onFocus() {
1603
+ return setIsSearchFocused(true);
1604
+ }
1524
1605
  })), /*#__PURE__*/React__default.createElement("button", {
1525
1606
  type: "button",
1526
1607
  onClick: onSearchClick
@@ -1530,14 +1611,24 @@
1530
1611
  className: "navbar__input-close-icon"
1531
1612
  })))), /*#__PURE__*/React__default.createElement(SearchResults, {
1532
1613
  searchValue: searchValue,
1533
- searchLoading: searchLoading,
1534
1614
  searchResults: searchResults,
1535
1615
  onViewAll: function onViewAll() {
1536
1616
  onSearchSubmit(searchValue);
1537
1617
  setSearchValue('');
1618
+ setSearchResults({
1619
+ brands: [],
1620
+ products: []
1621
+ });
1622
+ setIsSearchFocused(false);
1538
1623
  },
1539
1624
  onSearchSubmit: onSearchSubmit,
1540
- setSearchValue: setSearchValue
1625
+ setSearchValue: setSearchValue,
1626
+ searchResultsRef: searchResultsRef,
1627
+ initialSearchData: initialSearchView,
1628
+ isSearchFocused: isSearchFocused,
1629
+ setIsSearchFocused: setIsSearchFocused,
1630
+ currency: currency,
1631
+ currencySymbol: currencySymbol
1541
1632
  }), shop && /*#__PURE__*/React__default.createElement(LuxitySideNav, {
1542
1633
  accordionIcon: accordionIcon,
1543
1634
  logoSrc: logoSrc,