Skip to content

Commit 86153fc

Browse files
UI tweaks and fixes
1 parent 7674189 commit 86153fc

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

ui/src/Utils/time.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ function toTimeStr(diff) {
1010
return `${hoursStr}:${minutesStr}:${secondsStr}`;
1111
}
1212

13-
export function timeBetweenAsString({endTime=null, startTime=null}) {
13+
export function timeBetweenAsString({endTime=null, startTime=null, bounded=false}) {
1414
if (null === startTime) startTime = new Date();
1515
if (null === endTime) endTime = new Date();
1616

17-
const diff = endTime - startTime; // in ms
17+
let diff = endTime - startTime; // in ms
18+
if (bounded && (diff < 0)) diff = 0;
19+
1820
if (diff < 0) return '-' + toTimeStr(-diff);
1921
return toTimeStr(diff);
2022
}

ui/src/components/CurrentOperationInfoArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TimerArea from "./TimerArea";
55
export function CurrentOperationInfoAreaComponent({
66
isRunning, estimatedEndTime
77
}) {
8-
if (!isRunning) return null;
8+
estimatedEndTime = isRunning ? estimatedEndTime : null;
99
return (
1010
<div className="countdown-area">
1111
<TimerArea startTime={null} endTime={estimatedEndTime} />

ui/src/components/SystemControls.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
3-
import { Button } from 'react-bootstrap';
3+
import { Button, Container } from 'react-bootstrap';
44

55
import { useWaterPumpAPI } from '../contexts/WaterPumpAPIContext';
66
import { startPump, stopPump } from '../store/slices/SystemStatus.js';
@@ -19,14 +19,14 @@ export function SystemControlsComponent({
1919

2020
const isRunning = systemStatus.pump.running;
2121
return (
22-
<>
23-
<Button variant="primary" onClick={handleStart} disabled={isRunning}>
22+
<Container className="d-flex justify-content-center">
23+
<Button variant="primary" onClick={handleStart} disabled={isRunning} size="lg">
2424
Start
25-
</Button>{' '}
26-
<Button variant="secondary" onClick={handleStop} disabled={!isRunning}>
25+
</Button>
26+
<Button variant="secondary" onClick={handleStop} disabled={!isRunning} className='ms-5' size="lg">
2727
Stop
2828
</Button>
29-
</>
29+
</Container>
3030
);
3131
}
3232

ui/src/components/SystemStatusArea.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ function _systemStatus(status) {
99
}
1010

1111
const pump = status.pump;
12+
const color = pump.running ? "green" : "black";
1213
return (
1314
<>
1415
<strong>Time since last update:</strong>{' '}
1516
<TimerArea startTime={status.updated} />
16-
<br />
17-
<strong>Pump Running:</strong> {pump.running ? "Yes" : "No"}<br />
18-
<strong>Time Left:</strong> {pump.timeLeft} ms
17+
{' | '}
18+
<span style={{color: color}}>
19+
<strong>Pump Running:</strong> {pump.running ? "Yes" : "No"}
20+
</span>
1921
</>
2022
);
2123
}
2224

2325
export function SystemStatusAreaComponent({ status }) {
2426
return (
25-
<Card>
27+
<Card className="my-3">
2628
<Card.Body>
2729
<Card.Title>System Status</Card.Title>
2830
<Card.Text>

ui/src/components/TimerArea.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React from "react";
22
import { timeBetweenAsString } from "../Utils/time";
33

4-
export function TimerArea({ startTime=null, endTime=null, interval=450 }) {
4+
export function TimerArea({ startTime=null, endTime=null, interval=450, bounded=true }) {
55
const [countdown, setCountdown] = React.useState('');
66

77
React.useEffect(() => {
88
const tid = setInterval(() => {
9-
setCountdown(timeBetweenAsString({ startTime, endTime }));
9+
setCountdown(timeBetweenAsString({ startTime, endTime, bounded }));
1010
}, interval);
1111

1212
return () => clearInterval(tid);
13-
}, [startTime, endTime, interval]);
13+
}, [startTime, endTime, bounded, interval]);
1414

1515
return (
1616
<span className="timer-area">

ui/src/store/slices/Notifications.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ export const NotificationsSlice = createSlice({
77
},
88
reducers: {
99
alert: (state, action) => {
10-
state.currentNotifications = action.payload;
10+
const { message, ...rest } = action.payload;
11+
// prepend HH:MM:SS to message
12+
const now = new Date();
13+
const time = now.toTimeString().split(' ')[0];
14+
state.currentNotifications = {
15+
message: `[${time}] ${message}`,
16+
...rest
17+
};
1118
},
1219
clear: state => {
1320
state.currentNotifications = null;

ui/src/store/slices/SystemStatus.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export const SystemStatusSlice = createSlice({
6363
// on error, do not update system status
6464
builder.addCase(startPump.rejected, (state, action) => state);
6565
builder.addCase(stopPump.rejected, (state, action) => state);
66-
builder.addCase(updateSystemStatus.rejected, (state, action) => state);
66+
builder.addCase(updateSystemStatus.rejected, (state, action) => {
67+
return null;
68+
});
6769
}
6870
});
6971

0 commit comments

Comments
 (0)