-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a07170
commit 5eeb905
Showing
2 changed files
with
47 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<Button variant="primary" onClick={handleStart}> | ||
Start | ||
</Button>{' '} | ||
<Button variant="secondary" onClick={handleStop}> | ||
Stop | ||
</Button> | ||
</> | ||
); | ||
} | ||
|
||
export default SystemControls; |