@rabex-kit/rabex-ui 0.1.24 → 0.1.25

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.
@@ -536,42 +536,45 @@ var calculateTime = function calculateTime(time) {
536
536
  * @param ref
537
537
  * @returns
538
538
  */
539
- var useTime = function useTime(timestamp, isStart) {
540
- var TIMER;
541
- var _React$useState = React.useState(timestamp),
539
+ var useTime = function useTime(initialTimestamp, isStart) {
540
+ var _React$useState = React.useState(initialTimestamp),
542
541
  time = _React$useState[0],
543
542
  setTime = _React$useState[1];
544
- var _React$useState2 = React.useState(true),
543
+ var _React$useState2 = React.useState(false),
545
544
  isActive = _React$useState2[0],
546
545
  setIsActive = _React$useState2[1];
547
546
  React.useEffect(function () {
548
- if (time === 0) {
549
- clearInterval(TIMER);
550
- setIsActive(false);
551
- setTime(0);
552
- }
553
- }, [time]);
554
- React.useEffect(function () {
547
+ var TIMER;
555
548
  if (isStart && isActive) {
556
549
  TIMER = setInterval(function () {
557
550
  setTime(function (prev) {
551
+ if (prev <= 1000) {
552
+ clearInterval(TIMER);
553
+ setIsActive(false);
554
+ return 0;
555
+ }
558
556
  return prev - 1000;
559
557
  });
560
558
  }, 1000);
561
559
  }
562
560
  return function () {
563
- clearInterval(TIMER);
561
+ if (TIMER) {
562
+ clearInterval(TIMER);
563
+ }
564
564
  };
565
565
  }, [isStart, isActive]);
566
+ React.useEffect(function () {
567
+ if (isStart) {
568
+ setIsActive(true);
569
+ }
570
+ }, [isStart]);
566
571
  var reset = function reset() {
567
- clearInterval(TIMER);
568
- TIMER = null;
569
572
  setIsActive(true);
570
- setTime(timestamp);
573
+ setTime(initialTimestamp);
571
574
  };
572
575
  return {
573
576
  time: calculateTime(time),
574
- seconds: time / 1000,
577
+ seconds: Math.floor(time / 1000),
575
578
  isActive: isActive,
576
579
  reset: reset,
577
580
  isComplete: time === 0
@@ -661,7 +664,7 @@ var AlertTimer = function AlertTimer(_ref) {
661
664
  if (isComplete && onComplete) {
662
665
  onComplete();
663
666
  }
664
- }, [isComplete]);
667
+ }, [isComplete, onComplete]);
665
668
  return React.createElement(Stack$1, {
666
669
  flexDirection: "row",
667
670
  alignItems: "center",