fix reset active timer
This commit is contained in:
parent
a44da29cbd
commit
32b239459c
@ -120,10 +120,20 @@ class Timer extends Component {
|
||||
}
|
||||
|
||||
handleControlClick() {
|
||||
const { timer, startTimer, stopTimer } = this.props;
|
||||
const {
|
||||
timer, startTimer, stopTimer, timeOffset,
|
||||
} = this.props;
|
||||
|
||||
const {
|
||||
running,
|
||||
accumulated,
|
||||
timestamp,
|
||||
} = timer;
|
||||
|
||||
if (timer.running) {
|
||||
stopTimer(this.getTime());
|
||||
const elapsedTime = Service.getElapsedTime(running, timestamp, timeOffset, accumulated);
|
||||
|
||||
stopTimer(elapsedTime);
|
||||
} else {
|
||||
startTimer();
|
||||
}
|
||||
@ -160,17 +170,19 @@ class Timer extends Component {
|
||||
}
|
||||
|
||||
handleSwitchToStopwatch() {
|
||||
const { timer, switchTimer } = this.props;
|
||||
const { timer, stopTimer, switchTimer } = this.props;
|
||||
|
||||
if (!timer.stopwatch) {
|
||||
stopTimer(this.getTime());
|
||||
switchTimer(true);
|
||||
}
|
||||
}
|
||||
|
||||
handleSwitchToTimer() {
|
||||
const { timer, switchTimer } = this.props;
|
||||
const { timer, stopTimer, switchTimer } = this.props;
|
||||
|
||||
if (timer.stopwatch) {
|
||||
stopTimer(this.getTime());
|
||||
switchTimer(false);
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,8 @@ const TimerIndicator: React.FC<TimerIndicatorProps> = ({
|
||||
}, [running]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!running) return;
|
||||
|
||||
const timePassed = passedTime >= 0 ? passedTime : 0;
|
||||
|
||||
setTime((prev) => {
|
||||
@ -114,7 +116,7 @@ const TimerIndicator: React.FC<TimerIndicatorProps> = ({
|
||||
if (timePassed > prev) return timePassed;
|
||||
return prev;
|
||||
});
|
||||
}, [passedTime, stopwatch]);
|
||||
}, [passedTime, stopwatch, startedAt]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!timeRef.current) {
|
||||
@ -188,7 +190,7 @@ const TimerIndicatorContainer: React.FC = () => {
|
||||
|
||||
const { timer } = timerData;
|
||||
const [currentTimer] = timer;
|
||||
if (!currentTimer.active) return null;
|
||||
if (!currentTimer?.active) return null;
|
||||
|
||||
const {
|
||||
accumulated,
|
||||
|
Loading…
Reference in New Issue
Block a user