diff --git a/ui/src/App.js b/ui/src/App.js index 954b4b1..3a9d0d8 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -6,19 +6,39 @@ import NotificationsArea from './components/NotificationsArea.js'; import APIAddressField from './components/APIAddressField'; import PourTimeField from './components/PourTimeField'; import SystemControls from './components/SystemControls'; +import SystemStatusArea from './components/SystemStatusArea'; + +// TODO: Replace this with a real system status +// replace "water threshold" with "waterThreshold" +// replace "time left" with "timeLeft" +// add field "updated" +const systemStatus = { + waterThreshold: 1234, + pump: { + running: false, + timeLeft: 0, + }, + updated: new Date(), +}; function App() { const [pourTime, setPourTime] = useState(1000); - + // TODO: Add a fake countdown timer of timeLeft return (

Tea System UI

+ +
- - - + {(null === systemStatus) ? null : ( + <> + + + + )} +
diff --git a/ui/src/components/SystemControls.js b/ui/src/components/SystemControls.js index 961a053..77d014d 100644 --- a/ui/src/components/SystemControls.js +++ b/ui/src/components/SystemControls.js @@ -4,7 +4,7 @@ import { Button } from 'react-bootstrap'; import { useWaterPumpAPI } from '../contexts/WaterPumpAPIContext'; import { useNotificationsSystem } from '../contexts/NotificationsContext.js'; -function SystemControls({ pouringTime }) { +function SystemControls({ pouringTime, systemStatus }) { const waterPump = useWaterPumpAPI().API; const NotificationsSystem = useNotificationsSystem(); @@ -26,12 +26,13 @@ function SystemControls({ pouringTime }) { } }; + const isRunning = systemStatus.pump.running; return ( <> - {' '} - diff --git a/ui/src/components/SystemStatusArea.js b/ui/src/components/SystemStatusArea.js new file mode 100644 index 0000000..1519e39 --- /dev/null +++ b/ui/src/components/SystemStatusArea.js @@ -0,0 +1,38 @@ +import React from 'react'; +import { Card } from 'react-bootstrap'; + +// TODO: Update time since last update every second, +// currently it only updates when the status changes +function _systemStatus(status) { + if (null === status) { + return (Not connected); + } + + const pump = status.pump; + // TODO: check is this is a valid way to get the time since last update + const now = new Date(); + const diff = now - status.updated; + const diffString = new Date(diff).toISOString().substr(11, 8); + return ( + <> + Time since last update: {diffString}
+ Pump Running: {pump.running ? "Yes" : "No"}
+ Time Left: {pump.timeLeft} ms + + ); +} + +function SystemStatusArea({ status }) { + return ( + + + System Status + + {_systemStatus(status)} + + + + ); +} + +export default SystemStatusArea; \ No newline at end of file