Skip to content

Commit

Permalink
"Hold to pour" button added to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 13, 2024
1 parent 86153fc commit f9ae6cc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Binary file added ui/public/valve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions ui/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
text-align: center;
font-weight: bold;
font-size: 2rem;
}

.hold-to-pour-image {
object-fit: contain;
width: 25%;
height: auto;
}
2 changes: 2 additions & 0 deletions ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -23,6 +24,7 @@ function App({ isConnected }) {
<PourTimeField />
<CurrentOperationInfoArea />
<SystemControls />
<HoldToPour />
</>
) : null}
</Form>
Expand Down
40 changes: 40 additions & 0 deletions ui/src/components/HoldToPour.js
Original file line number Diff line number Diff line change
@@ -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 (
<Container className="d-flex justify-content-center mt-3">
<img src="valve.png" className='hold-to-pour-image' alt="Hold to pour button"
draggable="false" onMouseDown={handlePress} onMouseUp={handleRelease}
/>
</Container>
);
}

export default connect(
state => ({}),
{ startPump, stopPump }
)(HoldToPourComponent);

0 comments on commit f9ae6cc

Please sign in to comment.