Skip to content

Commit f9ae6cc

Browse files
"Hold to pour" button added to UI
1 parent 86153fc commit f9ae6cc

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

ui/public/valve.png

23.7 KB
Loading

ui/src/App.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
text-align: center;
77
font-weight: bold;
88
font-size: 2rem;
9+
}
10+
11+
.hold-to-pour-image {
12+
object-fit: contain;
13+
width: 25%;
14+
height: auto;
915
}

ui/src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import PourTimeField from './components/PourTimeField.js';
99
import SystemControls from './components/SystemControls.js';
1010
import SystemStatusArea from './components/SystemStatusArea.js';
1111
import CurrentOperationInfoArea from './components/CurrentOperationInfoArea.js';
12+
import HoldToPour from './components/HoldToPour.js';
1213

1314
function App({ isConnected }) {
1415
return (
@@ -23,6 +24,7 @@ function App({ isConnected }) {
2324
<PourTimeField />
2425
<CurrentOperationInfoArea />
2526
<SystemControls />
27+
<HoldToPour />
2628
</>
2729
) : null}
2830
</Form>

ui/src/components/HoldToPour.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { useState, useEffect } from 'react';
2+
import { connect } from 'react-redux';
3+
import { Container } from 'react-bootstrap';
4+
import { useWaterPumpAPI } from '../contexts/WaterPumpAPIContext';
5+
import { startPump, stopPump } from '../store/slices/SystemStatus.js';
6+
7+
export function HoldToPourComponent({ startPump, stopPump }) {
8+
const pouringTime = 1500;
9+
const api = useWaterPumpAPI().API;
10+
const [isPouring, setIsPouring] = useState(false);
11+
12+
useEffect(() => {
13+
if (!isPouring) return;
14+
15+
const tid = setInterval(() => {
16+
startPump({ api, pouringTime });
17+
}, pouringTime - 500);
18+
19+
return () => {
20+
clearInterval(tid);
21+
stopPump({ api });
22+
};
23+
}, [isPouring, api, startPump, stopPump]);
24+
25+
const handlePress = () => { setIsPouring(true); };
26+
const handleRelease = () => { setIsPouring(false); };
27+
28+
return (
29+
<Container className="d-flex justify-content-center mt-3">
30+
<img src="valve.png" className='hold-to-pour-image' alt="Hold to pour button"
31+
draggable="false" onMouseDown={handlePress} onMouseUp={handleRelease}
32+
/>
33+
</Container>
34+
);
35+
}
36+
37+
export default connect(
38+
state => ({}),
39+
{ startPump, stopPump }
40+
)(HoldToPourComponent);

0 commit comments

Comments
 (0)