@@ -16,12 +16,8 @@ import Radio from '@mui/material/Radio';
16
16
import RadioGroup from '@mui/material/RadioGroup' ;
17
17
import FormControlLabel from '@mui/material/FormControlLabel' ;
18
18
import FormControl from '@mui/material/FormControl' ;
19
-
20
- enum FuelType {
21
- E5 = 'e5' ,
22
- E10 = 'e10' ,
23
- Diesel = 'diesel'
24
- }
19
+ import GlobalState , { FuelType } from '../GlobalState' ;
20
+ import { useRecoilState } from 'recoil' ;
25
21
26
22
export interface GsPoint {
27
23
timestamp : string ;
@@ -41,8 +37,8 @@ export interface ChartProps {
41
37
42
38
export default function Chart ( props : ChartProps ) {
43
39
//console.log(props.timeSlots);
44
- const [ gsValues , setGsValues ] = useState ( [ ] as GsPoint [ ] ) ;
45
- const [ fuelType , setFuelType ] = useState ( FuelType . E5 ) ;
40
+ const [ gsValues , setGsValues ] = useState ( [ ] as GsPoint [ ] ) ;
41
+ const [ fuelTypeState , setfuelTypeState ] = useRecoilState ( GlobalState . fuelTypeState ) ;
46
42
const [ lineColor , setLineColor ] = useState ( '#8884d8' ) ;
47
43
const [ avgValue , setAvgValue ] = useState ( 0.0 ) ;
48
44
@@ -52,11 +48,11 @@ export default function Chart(props: ChartProps) {
52
48
} , [ ] ) ;
53
49
54
50
function updateChart ( ) {
55
- if ( fuelType === FuelType . E5 ) {
51
+ if ( fuelTypeState === FuelType . E5 ) {
56
52
setLineColor ( '#8884d8' )
57
53
setAvgValue ( props . timeSlots . reduce ( ( acc , value ) => value . e5 + acc , 0 ) / ( props . timeSlots . length || 1 ) ) ;
58
54
setGsValues ( props . timeSlots . map ( myValue => ( { timestamp : myValue . x , price : myValue . e5 - avgValue } as GsPoint ) ) )
59
- } else if ( fuelType === FuelType . E10 ) {
55
+ } else if ( fuelTypeState === FuelType . E10 ) {
60
56
setLineColor ( '#82ca9d' )
61
57
setAvgValue ( props . timeSlots . reduce ( ( acc , value ) => value . e10 + acc , 0 ) / ( props . timeSlots . length || 1 ) ) ;
62
58
setGsValues ( props . timeSlots . map ( myValue => ( { timestamp : myValue . x , price : myValue . e10 - avgValue } as GsPoint ) ) )
@@ -68,7 +64,7 @@ export default function Chart(props: ChartProps) {
68
64
}
69
65
70
66
const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
71
- setFuelType ( ( ( event . target as HTMLInputElement ) . value ) as FuelType ) ;
67
+ setfuelTypeState ( ( ( event . target as HTMLInputElement ) . value ) as FuelType ) ;
72
68
updateChart ( ) ;
73
69
} ;
74
70
return ( < div >
@@ -88,7 +84,7 @@ export default function Chart(props: ChartProps) {
88
84
row
89
85
aria-labelledby = "demo-row-radio-buttons-group-label"
90
86
name = "row-radio-buttons-group"
91
- value = { fuelType }
87
+ value = { fuelTypeState }
92
88
onChange = { handleChange }
93
89
>
94
90
< FormControlLabel value = { FuelType . E5 } control = { < Radio /> } label = "E5" />
0 commit comments