From 5eeb90557e6252ce850b523301aac7939b3f7508 Mon Sep 17 00:00:00 2001 From: GreenWizard2015 Date: Mon, 1 Jan 2024 22:20:15 +0000 Subject: [PATCH] SystemControls component --- ui/src/App.js | 32 +++++----------------- ui/src/components/SystemControls.js | 41 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 ui/src/components/SystemControls.js diff --git a/ui/src/App.js b/ui/src/App.js index 4b7c247..954b4b1 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -1,46 +1,26 @@ import React, { useState } from 'react'; import './App.css'; -import { Container, Form, Button } from 'react-bootstrap'; +import { Container, Form } from 'react-bootstrap'; -import { useWaterPumpAPI } from './contexts/WaterPumpAPIContext'; -import { useNotificationsSystem } from './contexts/NotificationsContext.js'; import NotificationsArea from './components/NotificationsArea.js'; import APIAddressField from './components/APIAddressField'; import PourTimeField from './components/PourTimeField'; +import SystemControls from './components/SystemControls'; function App() { - const waterPump = useWaterPumpAPI().API; - const NotificationsSystem = useNotificationsSystem(); const [pourTime, setPourTime] = useState(1000); - const handleStart = async () => { - try { - await waterPump.start(pourTime); - NotificationsSystem.alert('Water pump started successfully!'); - } catch (error) { - NotificationsSystem.alert('Error starting water pump: ' + error.message); - } - }; - - const handleStop = async () => { - try { - await waterPump.stop(); - NotificationsSystem.alert('Water pump stopped successfully!'); - } catch (error) { - NotificationsSystem.alert('Error stopping water pump: ' + error.message); - } - }; - return (

Tea System UI

-
- {' '} - + + +
+ ); } diff --git a/ui/src/components/SystemControls.js b/ui/src/components/SystemControls.js new file mode 100644 index 0000000..961a053 --- /dev/null +++ b/ui/src/components/SystemControls.js @@ -0,0 +1,41 @@ +import React from 'react'; +import { Button } from 'react-bootstrap'; + +import { useWaterPumpAPI } from '../contexts/WaterPumpAPIContext'; +import { useNotificationsSystem } from '../contexts/NotificationsContext.js'; + +function SystemControls({ pouringTime }) { + const waterPump = useWaterPumpAPI().API; + const NotificationsSystem = useNotificationsSystem(); + + const handleStart = async () => { + try { + await waterPump.start(pouringTime); + NotificationsSystem.alert('Water pump started successfully!'); + } catch (error) { + NotificationsSystem.alert('Error starting water pump: ' + error.message); + } + }; + + const handleStop = async () => { + try { + await waterPump.stop(); + NotificationsSystem.alert('Water pump stopped successfully!'); + } catch (error) { + NotificationsSystem.alert('Error stopping water pump: ' + error.message); + } + }; + + return ( + <> + {' '} + + + ); +} + +export default SystemControls; \ No newline at end of file