-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
countdown for operation and some refactoring
- Loading branch information
1 parent
6e34b97
commit fe49ff7
Showing
8 changed files
with
81 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
.App { | ||
} | ||
|
||
.countdown-area { | ||
width: 100%; | ||
text-align: center; | ||
font-weight: bold; | ||
font-size: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function toTimeStr(diff) { | ||
const seconds = Math.floor(diff / 1000); | ||
const minutes = Math.floor(seconds / 60); | ||
const hours = Math.floor(minutes / 60); | ||
|
||
const secondsStr = (seconds % 60).toString().padStart(2, '0'); | ||
const minutesStr = (minutes % 60).toString().padStart(2, '0'); | ||
const hoursStr = hours.toString().padStart(2, '0'); | ||
|
||
return `${hoursStr}:${minutesStr}:${secondsStr}`; | ||
} | ||
|
||
export function timeBetweenAsString({endTime=null, startTime=null}) { | ||
if (null === startTime) startTime = new Date(); | ||
if (null === endTime) endTime = new Date(); | ||
|
||
const diff = endTime - startTime; // in ms | ||
if (diff < 0) return '-' + toTimeStr(-diff); | ||
return toTimeStr(diff); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import TimerArea from "./TimerArea"; | ||
|
||
export function CurrentOperationInfoAreaComponent({ | ||
isRunning, estimatedEndTime | ||
}) { | ||
if (!isRunning) return null; | ||
return ( | ||
<div className="countdown-area"> | ||
<TimerArea startTime={null} endTime={estimatedEndTime} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default connect( | ||
state => ({ | ||
isRunning: state.systemStatus.pump.running, | ||
estimatedEndTime: state.systemStatus.pump.estimatedEndTime, | ||
}), | ||
[] | ||
)(CurrentOperationInfoAreaComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import { timeBetweenAsString } from "../Utils/time"; | ||
|
||
export function TimerArea({ startTime=null, endTime=null, interval=450 }) { | ||
const [countdown, setCountdown] = React.useState(''); | ||
|
||
React.useEffect(() => { | ||
const tid = setInterval(() => { | ||
setCountdown(timeBetweenAsString({ startTime, endTime })); | ||
}, interval); | ||
|
||
return () => clearInterval(tid); | ||
}, [startTime, endTime, interval]); | ||
|
||
return ( | ||
<span className="timer-area"> | ||
{countdown} | ||
</span> | ||
); | ||
} | ||
|
||
export default TimerArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters