-
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
9ed676e
commit 0a07170
Showing
2 changed files
with
45 additions
and
31 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,38 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Form, Row, Col } from 'react-bootstrap'; | ||
|
||
const STORE_POURRTIME = 'pourTime'; | ||
|
||
function PourTimeField({ onChange, min, max }) { | ||
const [pourTime, setPourTime] = useState(1000); | ||
|
||
useEffect(() => { | ||
const time = localStorage.getItem(STORE_POURRTIME); | ||
if (time) setPourTime(parseInt(time, 10)); | ||
}, []); // on mount | ||
// call onChange when pourTime changes | ||
useEffect(() => onChange(pourTime), [pourTime, onChange]); | ||
|
||
const handleChange = (event) => { | ||
let newTime = parseInt(event.target.value, 10); | ||
if (isNaN(newTime)) return; | ||
if (newTime < min) newTime = min; | ||
if (max < newTime) newTime = max; | ||
|
||
setPourTime(newTime); | ||
localStorage.setItem(STORE_POURRTIME, newTime); | ||
}; | ||
|
||
return ( | ||
<Form.Group as={Row} className="mb-3"> | ||
<Form.Label column sm="2"> | ||
Run Time (ms): | ||
</Form.Label> | ||
<Col sm="10"> | ||
<Form.Control type="number" value={pourTime} onChange={handleChange} /> | ||
</Col> | ||
</Form.Group> | ||
); | ||
} | ||
|
||
export default PourTimeField; |