@@ -4,45 +4,44 @@ import { useEffect, useState } from "react";
4
4
import { useTranslation } from "react-i18next" ;
5
5
import LanguageSelector from "../components/LanguageSelector/LanguageSelector" ;
6
6
7
- import './RefillTime .scss' ;
7
+ import './DripRate .scss' ;
8
8
import Home from "../components/Home/Home" ;
9
9
10
- export default function RefillTimeFormula ( ) {
10
+ export default function DripRateFormula ( ) {
11
11
const { t } = useTranslation ( ) ;
12
12
13
13
const [ motherSolutionVolume , setMotherSolutionVolume ] = useState < number > ( 0 )
14
14
const [ dripRate , setDripRate ] = useState < number > ( 0 )
15
15
const [ refillTime , setRefillTime ] = useState < number > ( 0 )
16
16
17
17
useEffect ( ( ) => {
18
- if ( dripRate <= 0 ) {
19
- setRefillTime ( 0 )
20
- return ;
21
- }
22
- setRefillTime ( motherSolutionVolume / dripRate )
23
- } , [ motherSolutionVolume , dripRate ] )
18
+ // The mother solution is in liters. The refill time is in days. We want the drip rate in milliliters per minute.
19
+ // We convert liters to milliliters and days to minutes and perform the division.
20
+ const calculatedDripRate = refillTime > 0 ? ( motherSolutionVolume * 1000 ) / ( refillTime * 1440 ) : 0
21
+ setDripRate ( calculatedDripRate )
22
+ } , [ motherSolutionVolume , refillTime ] )
24
23
25
24
return (
26
25
< div className = "center" >
27
26
< Home > </ Home >
28
- < h1 > { t ( 'Refill Time Formula' ) } </ h1 >
27
+ < h1 > { t ( 'Drip Rate Formula' ) } </ h1 >
29
28
< div className = "input-wrapper" >
30
29
31
30
< div className = "input-group" >
32
- < label > { t ( 'Mother Solution Volume' ) } </ label >
31
+ < label > { ` ${ t ( 'Mother Solution Volume' ) } ( ${ t ( 'L' ) } )` } </ label >
33
32
< input type = "number" value = { motherSolutionVolume } onChange = { ( event ) => { setMotherSolutionVolume ( Number ( event . target . value ) ) } } />
34
33
</ div >
35
34
36
35
< div className = "input-group" >
37
- < label > { t ( 'Drip Rate' ) } </ label >
38
- < input type = "number" value = { dripRate } onChange = { ( event ) => { setDripRate ( Number ( event . target . value ) ) } } />
36
+ < label > { ` ${ t ( 'Refill time' ) } ( ${ t ( 'days' ) } )` } </ label >
37
+ < input type = "number" value = { refillTime } onChange = { ( event ) => { setRefillTime ( Number ( event . target . value ) ) } } />
39
38
</ div >
40
39
41
- < h2 > { `${ t ( 'Refill time is' ) } : ${ refillTime } ${ t ( 'hours ' ) } ` } </ h2 >
40
+ < h2 > { `${ t ( 'Drip Rate is' ) } : ${ dripRate . toFixed ( 2 ) } ${ t ( 'milliliters' ) } / ${ t ( 'minute ') } ` } </ h2 >
42
41
43
42
< button className = "button" onClick = { ( ) => {
44
43
setMotherSolutionVolume ( 0 )
45
- setDripRate ( 0 )
44
+ setRefillTime ( 0 )
46
45
} } > { t ( 'Clear' ) } </ button >
47
46
</ div >
48
47
0 commit comments