@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.
@@ -11,7 +11,7 @@ declare type timerType = {
11
11
  * @param ref
12
12
  * @returns
13
13
  */
14
- declare const useTime: (timestamp: any, isStart: any) => {
14
+ declare const useTime: (initialTimestamp: number, isStart: boolean) => {
15
15
  time: timerType;
16
16
  seconds: number;
17
17
  isActive: boolean;
@@ -541,42 +541,45 @@ var calculateTime = function calculateTime(time) {
541
541
  * @param ref
542
542
  * @returns
543
543
  */
544
- var useTime = function useTime(timestamp, isStart) {
545
- var TIMER;
546
- var _React$useState = React__default.useState(timestamp),
544
+ var useTime = function useTime(initialTimestamp, isStart) {
545
+ var _React$useState = React__default.useState(initialTimestamp),
547
546
  time = _React$useState[0],
548
547
  setTime = _React$useState[1];
549
- var _React$useState2 = React__default.useState(true),
548
+ var _React$useState2 = React__default.useState(false),
550
549
  isActive = _React$useState2[0],
551
550
  setIsActive = _React$useState2[1];
552
551
  React__default.useEffect(function () {
553
- if (time === 0) {
554
- clearInterval(TIMER);
555
- setIsActive(false);
556
- setTime(0);
557
- }
558
- }, [time]);
559
- React__default.useEffect(function () {
552
+ var TIMER;
560
553
  if (isStart && isActive) {
561
554
  TIMER = setInterval(function () {
562
555
  setTime(function (prev) {
556
+ if (prev <= 1000) {
557
+ clearInterval(TIMER);
558
+ setIsActive(false);
559
+ return 0;
560
+ }
563
561
  return prev - 1000;
564
562
  });
565
563
  }, 1000);
566
564
  }
567
565
  return function () {
568
- clearInterval(TIMER);
566
+ if (TIMER) {
567
+ clearInterval(TIMER);
568
+ }
569
569
  };
570
570
  }, [isStart, isActive]);
571
+ React__default.useEffect(function () {
572
+ if (isStart) {
573
+ setIsActive(true);
574
+ }
575
+ }, [isStart]);
571
576
  var reset = function reset() {
572
- clearInterval(TIMER);
573
- TIMER = null;
574
577
  setIsActive(true);
575
- setTime(timestamp);
578
+ setTime(initialTimestamp);
576
579
  };
577
580
  return {
578
581
  time: calculateTime(time),
579
- seconds: time / 1000,
582
+ seconds: Math.floor(time / 1000),
580
583
  isActive: isActive,
581
584
  reset: reset,
582
585
  isComplete: time === 0
@@ -666,7 +669,7 @@ var AlertTimer = function AlertTimer(_ref) {
666
669
  if (isComplete && onComplete) {
667
670
  onComplete();
668
671
  }
669
- }, [isComplete]);
672
+ }, [isComplete, onComplete]);
670
673
  return React__default.createElement(Stack$1, {
671
674
  flexDirection: "row",
672
675
  alignItems: "center",