@@ -16,12 +16,8 @@ import Radio from '@mui/material/Radio';
1616import RadioGroup from '@mui/material/RadioGroup' ;
1717import FormControlLabel from '@mui/material/FormControlLabel' ;
1818import 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' ;
2521
2622export interface GsPoint {
2723 timestamp : string ;
@@ -41,8 +37,8 @@ export interface ChartProps {
4137
4238export default function Chart ( props : ChartProps ) {
4339 //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 ) ;
4642 const [ lineColor , setLineColor ] = useState ( '#8884d8' ) ;
4743 const [ avgValue , setAvgValue ] = useState ( 0.0 ) ;
4844
@@ -52,11 +48,11 @@ export default function Chart(props: ChartProps) {
5248 } , [ ] ) ;
5349
5450 function updateChart ( ) {
55- if ( fuelType === FuelType . E5 ) {
51+ if ( fuelTypeState === FuelType . E5 ) {
5652 setLineColor ( '#8884d8' )
5753 setAvgValue ( props . timeSlots . reduce ( ( acc , value ) => value . e5 + acc , 0 ) / ( props . timeSlots . length || 1 ) ) ;
5854 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 ) {
6056 setLineColor ( '#82ca9d' )
6157 setAvgValue ( props . timeSlots . reduce ( ( acc , value ) => value . e10 + acc , 0 ) / ( props . timeSlots . length || 1 ) ) ;
6258 setGsValues ( props . timeSlots . map ( myValue => ( { timestamp : myValue . x , price : myValue . e10 - avgValue } as GsPoint ) ) )
@@ -68,7 +64,7 @@ export default function Chart(props: ChartProps) {
6864 }
6965
7066 const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
71- setFuelType ( ( ( event . target as HTMLInputElement ) . value ) as FuelType ) ;
67+ setfuelTypeState ( ( ( event . target as HTMLInputElement ) . value ) as FuelType ) ;
7268 updateChart ( ) ;
7369 } ;
7470 return ( < div >
@@ -88,7 +84,7 @@ export default function Chart(props: ChartProps) {
8884 row
8985 aria-labelledby = "demo-row-radio-buttons-group-label"
9086 name = "row-radio-buttons-group"
91- value = { fuelType }
87+ value = { fuelTypeState }
9288 onChange = { handleChange }
9389 >
9490 < FormControlLabel value = { FuelType . E5 } control = { < Radio /> } label = "E5" />
0 commit comments