diff --git a/ui/public/valve.png b/ui/public/valve.png new file mode 100644 index 0000000..9b53ded Binary files /dev/null and b/ui/public/valve.png differ diff --git a/ui/src/App.css b/ui/src/App.css index 1c69a9f..2914275 100644 --- a/ui/src/App.css +++ b/ui/src/App.css @@ -6,4 +6,10 @@ text-align: center; font-weight: bold; font-size: 2rem; +} + +.hold-to-pour-image { + object-fit: contain; + width: 25%; + height: auto; } \ No newline at end of file diff --git a/ui/src/App.js b/ui/src/App.js index bb625c7..5f6949a 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -9,6 +9,7 @@ import PourTimeField from './components/PourTimeField.js'; import SystemControls from './components/SystemControls.js'; import SystemStatusArea from './components/SystemStatusArea.js'; import CurrentOperationInfoArea from './components/CurrentOperationInfoArea.js'; +import HoldToPour from './components/HoldToPour.js'; function App({ isConnected }) { return ( @@ -23,6 +24,7 @@ function App({ isConnected }) { + ) : null} diff --git a/ui/src/components/HoldToPour.js b/ui/src/components/HoldToPour.js new file mode 100644 index 0000000..2471575 --- /dev/null +++ b/ui/src/components/HoldToPour.js @@ -0,0 +1,40 @@ +import React, { useState, useEffect } from 'react'; +import { connect } from 'react-redux'; +import { Container } from 'react-bootstrap'; +import { useWaterPumpAPI } from '../contexts/WaterPumpAPIContext'; +import { startPump, stopPump } from '../store/slices/SystemStatus.js'; + +export function HoldToPourComponent({ startPump, stopPump }) { + const pouringTime = 1500; + const api = useWaterPumpAPI().API; + const [isPouring, setIsPouring] = useState(false); + + useEffect(() => { + if (!isPouring) return; + + const tid = setInterval(() => { + startPump({ api, pouringTime }); + }, pouringTime - 500); + + return () => { + clearInterval(tid); + stopPump({ api }); + }; + }, [isPouring, api, startPump, stopPump]); + + const handlePress = () => { setIsPouring(true); }; + const handleRelease = () => { setIsPouring(false); }; + + return ( + + Hold to pour button + + ); +} + +export default connect( + state => ({}), + { startPump, stopPump } +)(HoldToPourComponent); \ No newline at end of file