Skip to content

Commit

Permalink
UI tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 13, 2024
1 parent 7674189 commit 86153fc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
6 changes: 4 additions & 2 deletions ui/src/Utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ function toTimeStr(diff) {
return `${hoursStr}:${minutesStr}:${secondsStr}`;
}

export function timeBetweenAsString({endTime=null, startTime=null}) {
export function timeBetweenAsString({endTime=null, startTime=null, bounded=false}) {
if (null === startTime) startTime = new Date();
if (null === endTime) endTime = new Date();

const diff = endTime - startTime; // in ms
let diff = endTime - startTime; // in ms
if (bounded && (diff < 0)) diff = 0;

if (diff < 0) return '-' + toTimeStr(-diff);
return toTimeStr(diff);
}
2 changes: 1 addition & 1 deletion ui/src/components/CurrentOperationInfoArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TimerArea from "./TimerArea";
export function CurrentOperationInfoAreaComponent({
isRunning, estimatedEndTime
}) {
if (!isRunning) return null;
estimatedEndTime = isRunning ? estimatedEndTime : null;
return (
<div className="countdown-area">
<TimerArea startTime={null} endTime={estimatedEndTime} />
Expand Down
12 changes: 6 additions & 6 deletions ui/src/components/SystemControls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { Button } from 'react-bootstrap';
import { Button, Container } from 'react-bootstrap';

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

const isRunning = systemStatus.pump.running;
return (
<>
<Button variant="primary" onClick={handleStart} disabled={isRunning}>
<Container className="d-flex justify-content-center">
<Button variant="primary" onClick={handleStart} disabled={isRunning} size="lg">
Start
</Button>{' '}
<Button variant="secondary" onClick={handleStop} disabled={!isRunning}>
</Button>
<Button variant="secondary" onClick={handleStop} disabled={!isRunning} className='ms-5' size="lg">
Stop
</Button>
</>
</Container>
);
}

Expand Down
10 changes: 6 additions & 4 deletions ui/src/components/SystemStatusArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ function _systemStatus(status) {
}

const pump = status.pump;
const color = pump.running ? "green" : "black";
return (
<>
<strong>Time since last update:</strong>{' '}
<TimerArea startTime={status.updated} />
<br />
<strong>Pump Running:</strong> {pump.running ? "Yes" : "No"}<br />
<strong>Time Left:</strong> {pump.timeLeft} ms
{' | '}
<span style={{color: color}}>
<strong>Pump Running:</strong> {pump.running ? "Yes" : "No"}
</span>
</>
);
}

export function SystemStatusAreaComponent({ status }) {
return (
<Card>
<Card className="my-3">
<Card.Body>
<Card.Title>System Status</Card.Title>
<Card.Text>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/TimerArea.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from "react";
import { timeBetweenAsString } from "../Utils/time";

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

React.useEffect(() => {
const tid = setInterval(() => {
setCountdown(timeBetweenAsString({ startTime, endTime }));
setCountdown(timeBetweenAsString({ startTime, endTime, bounded }));
}, interval);

return () => clearInterval(tid);
}, [startTime, endTime, interval]);
}, [startTime, endTime, bounded, interval]);

return (
<span className="timer-area">
Expand Down
9 changes: 8 additions & 1 deletion ui/src/store/slices/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ export const NotificationsSlice = createSlice({
},
reducers: {
alert: (state, action) => {
state.currentNotifications = action.payload;
const { message, ...rest } = action.payload;
// prepend HH:MM:SS to message
const now = new Date();
const time = now.toTimeString().split(' ')[0];
state.currentNotifications = {
message: `[${time}] ${message}`,
...rest
};
},
clear: state => {
state.currentNotifications = null;
Expand Down
4 changes: 3 additions & 1 deletion ui/src/store/slices/SystemStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const SystemStatusSlice = createSlice({
// on error, do not update system status
builder.addCase(startPump.rejected, (state, action) => state);
builder.addCase(stopPump.rejected, (state, action) => state);
builder.addCase(updateSystemStatus.rejected, (state, action) => state);
builder.addCase(updateSystemStatus.rejected, (state, action) => {
return null;
});
}
});

Expand Down

0 comments on commit 86153fc

Please sign in to comment.