@copart/ops-tool-kit 1.10.0-alpha.27 → 1.10.0-alpha.28

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.
@@ -33,7 +33,7 @@ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
33
33
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
34
34
 
35
35
  const name$f = "@copart/ops-tool-kit";
36
- const version$5 = "1.10.0-alpha.27";
36
+ const version$5 = "1.10.0-alpha.28";
37
37
  const main$1 = "dist/ops-tool-kit.js";
38
38
  const style = "dist/ops-tool-kit.css";
39
39
  const files = [
@@ -37153,6 +37153,21 @@ var SanitizeNotificationContent = function SanitizeNotificationContent(str) {
37153
37153
  var regex = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>|<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi;
37154
37154
  return str.replace(regex, '');
37155
37155
  };
37156
+ var throttle = function throttle(func, delay) {
37157
+ var lastExecution = 0;
37158
+ return function () {
37159
+ var now = Date.now();
37160
+
37161
+ if (now - lastExecution >= delay) {
37162
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37163
+ args[_key] = arguments[_key];
37164
+ }
37165
+
37166
+ func.apply(this, args);
37167
+ lastExecution = now;
37168
+ }
37169
+ };
37170
+ };
37156
37171
 
37157
37172
  var useWindowSize = function useWindowSize() {
37158
37173
  var isClient = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object';
@@ -41736,25 +41751,35 @@ var getFirebaseConfig = function getFirebaseConfig() {
41736
41751
  // firebase.initializeApp(firebaseConfig)
41737
41752
  // }
41738
41753
 
41739
- function attachHandlers(firebase, updateNotifications, updateAllFirebaseNotificationsList) {
41754
+ function attachHandlers(firebase, updateNotifications, updateAllFirebaseNotificationsList, throttledFunction) {
41740
41755
  var today = getTodayDate();
41741
41756
  firebase.database().ref().child('ops-news').orderByChild('ends_at').startAt(today).on('value', function (snapshot) {
41742
- compose(updateNotifications, filterNotificationsFireBase, mapNotifications, values$1)(snapshot.val());
41743
- setTimeout(function () {
41744
- compose(updateAllFirebaseNotificationsList, mapNotifications, values$1)(snapshot.val());
41745
- }, 500);
41757
+ // compose(
41758
+ // updateNotifications,
41759
+ // filterNotificationsFireBase,
41760
+ // mapNotifications,
41761
+ // values,
41762
+ // )(snapshot.val())
41763
+ // setTimeout(()=>{
41764
+ // compose(updateAllFirebaseNotificationsList,mapNotifications,values)(snapshot.val())
41765
+ // },500)
41766
+ throttledFunction(updateNotifications, snapshot);
41746
41767
  });
41747
41768
  }
41748
41769
 
41749
41770
  var getFireBaseNotifications = function getFireBaseNotifications(updateNotifications, updateAllFirebaseNotificationsList) {
41750
- var firebaseConfig = getFirebaseConfig(); // connect(firebaseConfig)
41771
+ var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 60;
41772
+ var firebaseConfig = getFirebaseConfig();
41773
+ var throttledFunction = throttle(function (updateNotifications, snapshot) {
41774
+ compose(updateNotifications, filterNotificationsFireBase, mapNotifications, values$1)(snapshot.val());
41775
+ }, delay * 1000); // connect(firebaseConfig)
41751
41776
 
41752
41777
  var firebase;
41753
41778
  Promise.resolve().then(function () { return index_esm$1; }).then(function (module) {
41754
41779
  firebase = module.default;
41755
41780
  Promise.resolve().then(function () { return index_esm; }).then(function (module) {
41756
41781
  firebase.initializeApp(firebaseConfig);
41757
- attachHandlers(firebase, updateNotifications, updateAllFirebaseNotificationsList);
41782
+ attachHandlers(firebase, updateNotifications, updateAllFirebaseNotificationsList, throttledFunction);
41758
41783
  });
41759
41784
  });
41760
41785
  };
@@ -42187,14 +42212,17 @@ var AppBar = function AppBar(_ref) {
42187
42212
  setFirebaseinitialized = _useState20[1];
42188
42213
 
42189
42214
  var listOfAllNotificationsRef = React.useRef(listOfAllNotifications);
42215
+ var socketRetryCountRef = React.useRef(0);
42190
42216
  React.useEffect(function () {
42191
42217
  listOfAllNotificationsRef.current = listOfAllNotifications;
42192
42218
  }, [listOfAllNotifications]);
42193
42219
 
42194
42220
  var updateNotifications = function updateNotifications(newNotifications) {
42195
- setNotifications(function (notifications) {
42196
- return filterDuplicateAndSave(notifications, newNotifications);
42197
- });
42221
+ if (newNotifications.length) {
42222
+ setNotifications(function (notifications) {
42223
+ return filterDuplicateAndSave(notifications, newNotifications);
42224
+ });
42225
+ }
42198
42226
  };
42199
42227
 
42200
42228
  var filterOut = function filterOut(notifications, notificationToRemove) {
@@ -42331,11 +42359,10 @@ var AppBar = function AppBar(_ref) {
42331
42359
  };
42332
42360
 
42333
42361
  var selectedYard = (_storage$getSessionIt = storage$1.getSessionItem('dashboard')) === null || _storage$getSessionIt === void 0 ? void 0 : _storage$getSessionIt.selectedYard;
42334
- var socketRetryCount = 0;
42335
42362
 
42336
42363
  var reConnectSocket = function reConnectSocket() {
42337
- if (socketRetryCount < 15) {
42338
- socketRetryCount = socketRetryCount + 1;
42364
+ if (socketRetryCountRef.current < 15) {
42365
+ socketRetryCountRef.current = socketRetryCountRef.current + 1;
42339
42366
  socketClient && socketClient.close();
42340
42367
  setSocketClient(startWebSocketConnection(updateNotifications, updateAllNotificationsList, reConnectSocket));
42341
42368
  }
@@ -42344,7 +42371,7 @@ var AppBar = function AppBar(_ref) {
42344
42371
  var handleVisibilityChange = function handleVisibilityChange() {
42345
42372
  if (document.visibilityState === 'visible') {
42346
42373
  if (socketClient && socketClient.readyState !== WebSocket.OPEN) {
42347
- socketRetryCount = 0;
42374
+ socketRetryCountRef.current = 0;
42348
42375
  reConnectSocket();
42349
42376
  }
42350
42377
  }
@@ -42383,7 +42410,8 @@ var AppBar = function AppBar(_ref) {
42383
42410
  }
42384
42411
 
42385
42412
  if (!firebaseInitialized && notificationsSource.includes('Firebase')) {
42386
- getFireBaseNotifications(updateNotifications, updateAllFirebaseNotificationsList);
42413
+ var delay = coreAppConfig.firebaseTimerInSec || 60;
42414
+ getFireBaseNotifications(updateNotifications, updateAllFirebaseNotificationsList, delay);
42387
42415
  setFirebaseinitialized(true);
42388
42416
  }
42389
42417
  }