Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem in my code #2

Open
bibashkoirala opened this issue Apr 16, 2020 · 6 comments
Open

problem in my code #2

bibashkoirala opened this issue Apr 16, 2020 · 6 comments

Comments

@bibashkoirala
Copy link

bibashkoirala commented Apr 16, 2020

Good

@WisdomAyo
Copy link

there's a small issue on my code the countrypicker is not working after selecting a country and i've check the whole code i'm not missing anything

@imelendez
Copy link

there's a small issue on my code the countrypicker is not working after selecting a country and i've check the whole code i'm not missing anything

share the code here so we can take a look at it.

@WisdomAyo
Copy link

there's a small issue on my code the countrypicker is not working after selecting a country and i've check the whole code i'm not missing anything

share the code here so we can take a look at it.

import React, { useState, useEffect } from 'react';
import { NativeSelect, FormControl } from '@material-ui/core';

import { fetchCountries } from '../../api';

import styles from './CountryPicker.module.css';

const CountryPicker = ({ handleCountryChange }) => {
const [ fetchedCountries, setFetchedCountries ] = useState([]);
useEffect(() => {
const fetchAPI = async () => {
setFetchedCountries(await fetchCountries());

        };

        fetchAPI();
    }, []);

return(
   <FormControl className={styles.formControl}>
       <NativeSelect defaultValue="" onChange={(e) =>  handleCountryChange=(e.target.value) }>
           <option value=""> Global</option>
{fetchedCountries.map((country, i) => <option key={i} value={country}>{country}</option>)}
       </NativeSelect>
   </FormControl>
);

};

export default CountryPicker;

@WisdomAyo
Copy link

import React from 'react';
import { Card, CardContent, Typography, Grid } from '@material-ui/core';
import CountUp from 'react-countup';
import cx from 'classnames';

import styles from './Cards.module.css';

const Cards = ({ data : { confirmed, recovered, deaths, lastUpdate } }) => {

if (!confirmed){
    return 'loading.....';
}

return(



<Grid item component={Card} xs={12} md={3} className={cx(styles.card, styles.infected)}>

Infected Case

<CountUp
start={ 0}
end={confirmed.value}
duration={2.5}
separator=","
/>

{new Date(lastUpdate).toDateString()}
Number of AcTive case of Covid-19

  </Grid>

  <Grid item component={Card} xs={12} md={3} className={cx(styles.card, styles.recovered)}>
                    <CardContent>
      <Typography color="textSecondary" gutterBottom>Recovered Case</Typography>
      <Typography variant="h5">
           <CountUp
              start={ 0}
              end={recovered.value}
              duration={2.5}
              separator=","
        />
           </Typography>
      <Typography color="textSecondary">{new Date(lastUpdate).toDateString()}</Typography>
      <Typography variant="body2">Number of Recoveries From  COVID-19   </Typography>
     </CardContent>
      </Grid>

  <Grid item component={Card} xs={12} md={3} className={cx(styles.card, styles.deaths)}>
      <CardContent>
      <Typography color="textSecondary" gutterBottom>Deaths Case</Typography>
     <Typography variant="h5">
     <CountUp
              start={ 0}
              end={deaths.value}
              duration={2.5}
              separator=","
        />
       </Typography>
     <Typography color="textSecondary">{new Date(lastUpdate).toDateString()}</Typography>
     <Typography variant="body2">Number of Deaths caused By COVID-19   </Typography>
     </CardContent>
     
 </Grid>
            </Grid>
    </div>
);

};

export default Cards;

@WisdomAyo
Copy link

import React, { useState, useEffect } from 'react';
import { fetchDailyData } from '../../api';
import { Line, Bar } from 'react-chartjs-2';
import styles from './Chart.module.css';

const Chart = ({ data: {confirmed, deaths, recovered }, country }) => {
const [dailyData, setDailyData] = useState([]);

useEffect(() => {
    const fetchAPI = async () => {
      const initialDailyData = await fetchDailyData();

      setDailyData(initialDailyData);
    };

        

        fetchAPI(); 
    
}, []);  

const lineChart = (
 dailyData.length 
  ?( 
  <Line
    data={{
        labels:  dailyData.map(({ date }) => date),
        datasets: [{
            data: dailyData.map(({ confirmed}) => confirmed),
            label: 'Infected',
            borderColor: '#3333ff',
            fill: true,
        }, {
            data: dailyData.map(({ deaths}) => deaths),
            label: 'Deaths',
            borderColor: 'red',
            backgroundColor: 'rgba(255, 0, 0, 0.5)',
            fill: true, 

        }],
    }}
    />): null
);


const  barChart = (
     confirmed
    ?(
        <Bar 
            data={{
                    labels:['Infected', 'Recovered', 'Deaths'],
                    datasets: [{
                        label: 'People',
                        backgroundColor:['rgba(0, 0, 255, 0.5)', 'rgba(0, 255, 0, 0.5)', 'rgba(255, 0, 0, 0.5)' ],
                        data:[ confirmed.value, recovered.value, deaths.value ],
                    },
                ],
            }}
            options={{
                legend: {display: false},
                title:{display:true, text:`Current state in ${country}`},
            }}
        />
    ) : null
);
return(
    <div className={ styles.container}>
           {country ? barChart: lineChart } 
    </div>
)

}

export default Chart;

@chrc
Copy link

chrc commented Oct 28, 2020

What about App.js and your console log error please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants